Blog CeON-u » geek http://blog.ceon.pl Blog Centrum Otwartej Nauki Fri, 30 Aug 2013 20:09:45 +0000 en-US hourly 1 http://wordpress.org/?v=3.5.1 R with Vim http://bc.bojanorama.pl/2010/12/r-with-vim/ http://bc.bojanorama.pl/2010/12/r-with-vim/#comments Thu, 02 Dec 2010 17:49:11 +0000 MichaƂ http://brokeringclosure.wordpress.com/?p=344 For all those who think that Vim is The Editor for text files, and simultaneously think that R is The EnvironmentForStatisticalAnalysisAndGraphics.

After trying out various options for intergrating Vim with R I settled on the following configuration:

  1. Use Vim-R-pluginfor editing R code files, R documentation files (*.Rd) as well as the Sweave files. Apart from syntax highlighting the plugin allows to open an R console in a separate window and operate it with keyboard shortcuts from Vim (no need for frequent alt-tabbing etc.). Among other things you can:
    • Execute individual code lines, visually selected portions, or whole R code files in the R console.
    • Putting a cursor on a function name in the code file and: display its R help page, or display function arguments (through args()).
    • Put a cursor on any R object in the code file and perform frequently used functions: str, summary, plot, print, names…
    • List the content of the R Workspace
    • Clean the R Workspace
  2. I use Sweave quite extensively. For Sweave files the Vim-R-plugin provides the same keyboard mappings as for the R code files as well as nicely highlights both the LaTeX code and the R code in the code chunks. As my Sweave files have mostly LaTeX code with rather short R code snippets I would like to take advantage of another Vim plugin: the LaTeX-Suite. By default Vim will not load the Latex-suite for Sweave files, which is a HUGE disadvantage.

Vim and R using Vim-R-Plugin in action

Here is a way how to use both plugins simultaneously for Sweave files. The instruction applies to Ubuntu (so probably any Linux-like system). On Windows the ~/.vim directory corresponds to the ‘vimfiles’ directory, which most likely is something like ‘c:Program FilesVimvimfiles’. So:

  1. Install Vim-R-plugin normally.
  2. Install Latex-suite normally.
  3. In ~/.vim/ftplugin remove the symbolic link ‘rnoweb.vim’ and replace it with a normal text file with the following content:
runtime! ftplugin/r.vim
runtime! ftplugin/tex_latexSuite.vim

This will essentially load both plugins one after another. QED.

Edit

See here how to set it up on Mac

]]>
http://bc.bojanorama.pl/2010/12/r-with-vim/feed/ 0