Vim Tips Wiki


1,624pages on
this wiki
Add New Page

Use this page to discuss script 2628 Vim-R-plugin2: plugin to work with R

  • Add constructive comments, bug reports, or discuss improvements (see the guideline).
  • Do not document the script here (the author should do that on
  • This page may be out of date: check the script's page above, and its release notes.


Great plugin! I use it on Sweave files, along with the latex-suite. I have a problem though : I cannot run the Sweave and Pdf command (from the menu or the \sp mapping) since vim complains and returns me a "Too many arguments for function: RMakePDF".

Any help appreciated, thanks!

Could you please tell me what happens if you change line 105 of ftplugin/r.vim from:

   call RCreateMaps("nvi", '<Plug>RMakePDF',     'sp', ':call RMakePDF()')


   call RCreateMaps("nvi", '<Plug>RMakePDF',     'sp', ':call RMakePDF("nobib")')


If your Vim session's working directory is not the directory containing the R-file you are working with, the commands to send lines that require writing a temp file will fail because a '/' will be inserted into the temp file's name. (reported on Mac OS X) --16:48, August 3, 2010

Above fixed in version 100803. --Preceding unsigned comment added by Jalvesaq 10:08, November 14, 2010

Everything is working for me except for the help and object browser features. These would be really helpful. I'm using R 2.12.0 on debian, with vim 7.1.314 and the "screen" program. I would like the help to appear in the vim window so that I can send examples to the R window. I've tried it both with the tools package loaded and unloaded, which seemed relevant. When I do \rh I get these error messages. In the R window:

> source('/var/lib/vim/addons/r-plugin/vimhelp.R') ;'by', L)
Error in tools::Rd2txt_options(width = w) : object 'L' not found

In the vim window:

Error detected while processing function RAction..ShowRDoc..SetRTextWidth:
line   45:
E767: Too many arguments to printf()

The g:rplugin_htw does not seem to be sent to the function. If I change the R command to something random like'by', 80L) then I get other errors. Am I missing something obvious or some aspect of the installation? --Preceding unsigned comment added by Loren9 21:01, November 21, 2010

I use Gvim 7.3 under Windows XP 64bit Server 2003 (Service Pack 2) with Python 2.7.1. The R-Plugin seems to work but when I open a .R file I get an error message from the Microsoft Visual C++ Runtime Library:

Runtime Error!
Program: C:\Program Files (x86)\Vim\vim73\gvim.exe
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.

If I click "Ok" it works properly as far as I can see, however getting the error message every time is a bit annoying. --Preceding unsigned comment added by Peinzinger 15:56, April 21, 2011

I get the same error. --18:29, June 20, 2011
I was getting the same error on XP pro SP3 (32 bit) with gvim 7.3 and both python 2.7 and 3.1. The R6034 error is caused by pywin32. See Installing build 214 (over 216) appears to solve the problem. --16:45, August 11, 2011

When I launch R from within Vim using R-Plugin, I expect that the working directory in R should automatically be set to the path of the current Vim buffer, according to the code in $HOME/.vim/r-plugin/common_global.vim. However, it is not. Instead, it is set to my home directory.

Within Vim, ':!echo %:p' yields the desired path, but for some reason this path isn't getting inherited by Vim. I'm using R-Plugin 0.9.6 in MacVim Snapshot 63 (Vim 7.3) with GUI 1.42 (R 2.14.0) on Mac OSX Lion 10.7.2.

I suspect it may have something to do with the "Initial Working Directory" preference, which is set to my home directory. may somehow be overriding the working directory command that R-Plugin is attempting to set. Any ideas?

It appears that the problem is not specific to the GUI. I edited common_global.vim, telling it to use a non-gui R, and this R version exhibits the same problem described above. Also, I tried the current developmental version of R-Plugin, and the same problem occurs with it as well. --20:21, January 27, 2012
In taking a closer look at the relevant code in $HOME/.vim/r-plugin/common_global.vim, it occurs to me that I may be misunderstanding how R-Plugin is supposed to work, when it comes to setting the path of the current Vim buffer. It appears that this isn't even supposed to happen automatically when a Vim instance is launched, but only after the command '\rd' is passed to R from a Vim buffer.
If this is right, I'd like to change this bug report to a feature request. Namely, I think it makes a lot of sense to 1.) automatically change the current working directory in R to the directory containing the current Vim buffer when R is launched from within Vim using R-Plugin ('\rf') and 2.) to automatically load .RData and and .Rhistory (or .Rapp.history, for Mac users using, if the directory contains these files.
If I can figure out Vim scripting within the next week or so, I may submit a patch against common_global.vim to add these features. --08:46, January 28, 2012

For me it seems, that sending a visual block with \ss to R is not working as expected. For example, if I have a commented block and want to send to it to R for evaluation, the whole lines are sent. Leading to not being evaluated, caused by the comment --Feb, 2012

Sorry but I don't know how to get only the block. I'm using getline("'<", "'>") to get the selected lines (Jakson, February 12, 2012).

The \rn command was resulting in an error that the "vim.names" function wasn't found in R. I changed lines 2432 and 2457 of the .vim/r-plugin/common_global.vim file to remove "vim." and just have the statement read ':call RAction("names")'. Seems to work fine now, but this is my first time using this plugin, so maybe I misunderstood something. (Echo, 21 Jan, 2013)

Connect to an R sessionEdit

This script is a huge help; I use it every day. One feature I would love to see would be an option to connect to an R session within an already-running screen session. I occasionally program on remote machines via ssh, so I can't launch a new terminal but I can start a screen-R session separately and connect to it later. I have tinkered with this myself but my programming skills leave much to be desired. --19:26, October 5, 2010

Please, read the section Integration with screen.vim (:h vimrplugin_screenplugin). There is an explanation on how to detach a screen session. You can also use the Conque Shell plugin. Then you would simply start Vim with the command "screen vim". --Preceding unsigned comment added by Jalvesaq 10:13, November 14, 2010

Vim-R-Plugin and LaTeX-suiteEdit

Thanks for this script! It's a life changer for me (on Ubuntu). One question though: My Sweave files usually have more text than R code. There is more LaTeX code than R code. Consequently there is more latex coding than R coding for me. In that context latex-suite plugin is indispensable. Is there a way to take advantage of both plugins (vim-r and latex-suite) simultaneously?

  1. Have both LaTeX code and R code highlighted
  2. latex-suite mappings working (inserting environments etc)
  3. vim-r-plugin mappings working as well to be able to execute some R code etc.

Now that I think of it perhaps it would have been beneficial to split the vim-r-plugin in the usual way, i.e. separate scripts for syntax highlighting, key mappings etc. so that they can be used separately as well. --16:17, December 2, 2010

Some of the syntax and indent scripts are now on the official Vim runtime and they may be dropped from the .zip distribution of the Vim-R-plugin about one year after a new version of Vim is officially released. They will be kept on the github repository, though.

Installation problemsEdit

Somehow I cannot seem to get the r-plugin to work, after all installation steps have been completed I use \rf to start and it gives me the following error:

Error detected while processing function screen#ScreenShell..<SNR>32_ScreenInit:
line   85:
tmux: option requires an argument -- t^@usage: select-pane [-DLRU] [-t target-pane]^@
Press ENTER or type command to continue

Any ideas? --21:13, August 23, 2011

Same problem with me

Tmux 1.3 is incompatible with screen plugin 1.5. You have to either upgrade Tmux to 1.5 or downgrade screen plugin to 1.4.

Wish listEdit

  • Support for the R-package inlinedocs, to document code inline; nice would be also folding on comment sections like in the vim-pandoc plugin -- Febuary 10, 2012
I don't use inlinedocs. So, please explain what specifically you want. You could send an email to me with an R script with the code indented as you want and explain where it should be folded. If it's an easy thing to do, I'll write the code into indent/r.vim and syntax/r.vim. However, if it requires to much time, I'm sorry, but I would wait for a patch (Jakson, February 12, 2012).
  • Turn vim-r-plugin into a more general plugin, supporting other Read-Eval-Print-Loop languages, like haskell (ghci), ruby (irb) or lisp (clisp) -- Febuary 10, 2012
Please get the last github version. I have just made it easier to use the plugin as a general one. There is basic support for a few specific languages (python, ruby, haskell and lisp) in the file r-plugin/global_r_plugin.vim which should be copied to ~/.vim/plugin and edited as needed by the user (Jakson, February 14, 2012).
Thank you, that works great (Michel, February 20, 2012)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki