R.vim : Send R code from a VIM buffer to R
| script karma
Downloaded by 4586
Comments, bugs, improvements
script versions (upload new version)
|The plugin is not maintained any more. Please use the excellent vimscript #2628. It even lets you use the "r" key to send a visual selection to R (let vimrplugin_map_r=1) if you got used to this using my plugin. The following is only kept for archiving purposes.
Send R code from a VIM buffer to R on Unix type systems using funnel.pl from vimscript #221. Contains
Fernando Henrique Ferraz Pereira da Rosa is now a coauthor of this plugin (starting from version 0.03). He helped me fixing a bug and started the syntax file for mixed highlighting of Latex and R syntax (syntax/rnoweb.vim).
I set up a small project page for this plugin, featuring a screenshot:
You can browse the subversion repository where these files are at home: http://kriemhild.uft.uni-bremen.de/viewcvs/?root=vim
Alternatives for Mac Os X include vimscript #1741 and vimscript #2104.
Under Windows, I am now using a quite simple solution, consisting of the installation of the rcom package for R which requires statconnDCOM from http://rcom.univie.ac.at and ActiveState Perl in the PATH (watch out if you use R tools, because GNU perl does not have the DCOM interface, so ActiveState perl needs to be first in the path).
My ftplugin/r.vim under Windows:
perl << EOF
my $R = Win32::OLE->GetActiveObject('RCOMServerLib.StatConnector')
vnoremap <buffer> r "*y:perl rsourceclipboard<CR>
This means that the visual selection is pasted to the clipboard and the clipboard content is sourced by R when the key "r" is pressed in visual mode.
|For working with vim and R it is convenient to open a fresh xterm on a
fresh virtual desktop, covering the left half of the screen, and start vim,
check if the filetype is set correctly (:set ft), set it if necessary (e.g.
with :set ft=r) and press <F2>. This will open a second xterm listening to an R
interpreter. You can then send visually highlighted code from vim to R with
the vmap "r".
Caution: If there are adjacent tabs in the source code (can be made visible
with :set list, then they show up as ^I^I), then your R console will list
the contents of your working directory in the middle of interpreting your
code and most likely get confused. I don't recommend using tabs anyway (use
the vim option expandtab, as set in r.vim). A workaround for existing code
is to execute it with the R command source().
As an alternative to this plugin on www.vim.org you can also install my Debian
package if you are using the Debian distribution:
$ echo "deb http://www.uft.uni-bremen.de/chemie/ranke/debs ./" >> /etc/apt/sources.list
$ apt-get update
$ apt-get install vim-r-plugin
Note that you have to activate addons like this plugin since vim version
7.1-022+1, July 2007. For system-wide activation, use
$ vim-addons -w install r-plugin
(details in README.Debian). You can then ignore the rest of this file.
Making this plugin work requires the installation of the perl script,
ftplugin/funnel.pl. It just has to be in your $PATH and executable, so if you
are the only one working with the plugin on your machine, e.g.
mv ftplugin/funnel.pl ~/bin
chmod +x ~/bin/funnel.pl
(be sure ~/bin is in your $PATH variable) or if you have superuser privileges
you can put funnel.pl it into /usr/local/bin.
funnel.pl requires two perl libraries:
IO::Pty and Term::ReadLine
If you add the lines
au BufNewFile,BufRead *.R setf r
au BufNewFile,BufRead *.R set syntax=r
to your ~.vim/filetype.vim file (or create one with only these lines) then the
vimscript r.vim will be activated upon opening any file with a filename
matching *.R. The whole set of commands available at this point is elucidated
I am also including my syntax files for R help files and R noweb files (Sweave files)
as well as a Makefile for processing R noweb files from within vim with :make. The
syntax files are part of vim starting from version 7.
I have one report of the funnel.pl not working on Mac OS X with the default perl on this
OS. If anybody gets this to work, please drop me a line.
Click on the package to download.
ip used for rating: 184.108.40.206
||- Cleaned up ftplugin/*.vim files
- Added shiftwidth=2 and expandtab to ftplugin/rnoweb.vim
- Added documentation on using vim-addon-manager to activate the plugin under Debian based distributions
||- Update of R help file syntax for new items in R 2.3.0
- Fixed tabbing in ftplugin/r.vim to suit emacs edited scripts.
- Added a note about the problem with adjacent tabs being pasted to the R console (see README.R_with_vim)
- Small fixes
||- Up-to-date version of the R help and R noweb syntax files. Both of them are now part of vim 7.
- Added ftplugin/rnoweb.vim and Makefile.rnoweb for R noweb files.
||- switched to funnel.pl from VIlisp 2.3
- carefully reviewed and extended the R help file syntax highlighting
||Fixed the problem with the xterm not closing. Installation is also easier now because the bash script R-managed is not needed any more.
||Fernando Henrique Ferraz Pereira da Rosa inspired me to improve the
plugin. Also added mixed syntax highlighting for Sweave files according
to the tip of his.
||Small improvement of README file