sponsor Vim development Vim logo Vim Book Ad

rcom : Evaluate R (www.r-project.org) code via rcom, rserve, screen, or tmux

 script karma  Rating 0/0, Downloaded by 2408  Comments, bugs, improvements  Vim wiki

created by
Tom Link
 
script type
ftplugin
 
description
The rcom ftplugin uses one of the following methods to evaluate R code:

    screen ... default method; works under Linux & Windows (with cygwin/mintty & Windows Rterm)
    screen or tmux ... via the screen vim plugin; works under Linux & Windows
    RServe ... requires +ruby and the rserve-client rubygem; works under Linux & (less reliably) under Windows
    RCom interface ... requires http://rcom.univie.ac.at; works under Windows

With the exception of RCOM, most methods should work also under Mac OS
but that was not tested.

After installation, interaction with R is enabled for all
buffers with filetype r. For other filetypes, you can use the
functions |rcom#EvaluateInBuffer()|.


Features:

    - Evaluate R code
    - Operator map
    - Maps for normal, visual, and insert mode
    - Keyword map (|K|)
    - Inspect & edit/fix object (<LocalLeader>K)
    - Debug functions

The following features are supported only with some methods:

    - Omnicompletion for R
    - Get return values from R


Maps~

The ftplugin provides several maps (see also |g:rcom_map|,
|g:rcom_mapp|) to evaluate R code and optionally print the result in
normal, insert, and visual mode. There is also an operator (see
|g:rcom_mapop|).

Default Maps:
    <c-cr>    ... Evaluate the current line
    <c-s-cr>  ... Evaluate the current line & print result
    +.        ... Evaluate the current line (normal mode)
    +{motion} ... Operator
    [visual]+ ... Evaluate the visual area
    +p        ... Toggle printing for the above maps
    +d        ... Toggle a function's debug status
    +l        ... Open the log window
    ++        ... Evaluate the |maparg| previously mapped to +
    K         ... Info on the word under cursor
    <LocalLeader>K ... Inspect/edit/fix the object under cursor


Normal usage~

    0.  Optional steps:
            a. Prepare a running instance of RGui if using the RCOM
               method.
            b. RCOM and screen methods: The results get printed in the R
               window. You might want to arrange the windows in a way,
               so that you can see VIM, R console and R graphic device
               at the same time.
    1.  Open an R source file in VIM.
    2a. Type <c-cr> to evaluate the current line/visual area in R.
    2b. Type [count]+ or +{motion} to evaluate some text in R. (You can
        type ++ to invoke |+|.)
 
install details
Requirements:

    - R

RCOM method:

    - Windows only (because of rcom)
    - A ruby-enabled version of vim -- :echo has('ruby') must print 1
    - A suitable version of rcom (http://rcom.univie.ac.at). The rcom
      library has to be loaded in vim, which should be the default
      behaviour after installing rcom. The following code snippet must
      not throw an error: >

      :ruby require 'win32ole'; r = WIN32OLE.new("StatConnectorSrv.StatConnector"); r.Init("R"); r.Close

RServe method:

    - A ruby-enabled version of vim -- :echo has('ruby') must print 1
    - R rserve library installed
    - rserve-client rubygem installed

Screen method:

    - screen
    - For tmux: Eric Van Dewoestine's screen vim plugin installed (see
      http://www.vim.org/scripts/script.php?script_id=2711)
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
rcom.vba 0.03 2012-07-20 7.0 Tom Link - .gitignore
- g:rcom_r_plugin_compatibility: Use maps somewhat similar to the r-plugin (untested)
- Support alternative methods to connect to R: rserve and screen/tmux
- RDebug/RUndebug commands
- screen: rcom's own simplified method to use screen (now the default method)
- Method = screen: Support for gvim @ linux & gnome-terminal
- g:rcom#reuse = g:rcom#method == 'rcom'
- g:rcom#r_object_browser = 'str'
- Use rcom_vim.R
- g:rcom#screen#rterm = executable('Rterm') ? 'Rterm --ess' : 'R'
- s:reuse = g:rcom#reuse || !has("gui_running")
- g:rcom#screen#rcom_session replaces g:rcom#screen#rcom_args
- g:rcom#screen#rcom_sep = 0
- Make rcom/screen work also on the terminal
- s:Scratch() takes buffer "type" as an argument
- rcom#EvaluateInBuffer(): Show the transcript if the transcript buffer is visible or when running vim as server
- Highlight debugged functions
- rcom#Debug(fn): Toggle the debug status
- g:rcom#options = 'warn = 1'
- Connect & Disconnect return 1 when they created / closed an instance of R
- rcom.options
- screen/rcom: Better timing; make sure not to miss commands
- screen/rcom: set s:tempfile only once
- rcom_vim.R
- rcom_vim.R: Fixed checks for "reuse"
- g:rcom#screen#rcom_shell is a format string
- Improved timing (use msgwait=0 and sleep for g:rcom#screen#rcom_shell seconds in order not to miss a subsequent eval)
- rcom#Quit(): Remove buffer-local autocommand
- rcom/screen: set msgwait & msgminwait to 0 (reset on disconnect)
- rcom/screen: When waiting for a response, also check the file size &, if mode == 'r', the file content
- g:rcom#options: if has('gui_running') set help_type = "html"
- rcom.complete()
- rcom#Keyword(): Pass name and name as string as argument
- rcom#Info(): Call rcom#EvaluateInBuffer() with mode = ''
- Fix missed disconnect when using multiple R buffers
- Filename conversion (e.g. via cygpath)
- screen/rcom: Always use -S for gvim
- rcom/screen: Run -wipe with session info
MD5 checksum: f45fe4fdf1e8876ec0549e7572026227
rcom.vba.gz 0.2 2010-03-09 7.0 Tom Link - Add cursor markers only if w:tskeleton_hypercomplete exists
- g:rcom#reuse: If 0, don't use a running instance of R GUI (transcribe the results in VIM; be aware that some problems could cause problems)
- If there is a vim server named RCOM running, evaluate R code remotely (this won't block the current instance of gvim)
- Use g:rcom#server to start an instance of gvim that acts as server/proxy
- Transcript, log
rcom.vba.gz 0.1 2010-02-25 7.0 Tom Link Initial upload
ip used for rating: 142.132.191.50

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github