-
Notifications
You must be signed in to change notification settings - Fork 1
Options
Option | Description |
---|---|
R_auto_start | Start R automatically |
R_objbr_auto_start | Start the Object Browser automatically |
R-built-in-terminal | Options to control Vim's built-in terminal |
R_external_term | Command to run R in an external terminal emulator |
R_silent_term | Do not show terminal errors |
R_set_home_env | Set the value of $HOME for R (Windows only) |
R_save_win_pos | Save positions of R and GVim windows (Windows only) |
R_arrange_windows | Restore positions of R and GVim windows (Windows only) |
R_assign | Convert _ into <-
|
R_assign_map | Choose what to convert into <-
|
R_rnowebchunk | Convert < into <<>>=\n@ in Rnoweb files |
R_rmdchunk | Convert grave accent chunk into delimiters in Rmd files |
R_objbr_place | Placement of Object Browser |
R_objbr_w | Initial width of Object Browser window |
R_objbr_h | Initial height of Object Browser window |
R_objbr_opendf | Display data.frames open in the Object Browser |
R_objbr_openlist | Display lists open in the Object Browser |
R_objbr_allnames | Display hidden objects in the Object Browser |
R_nvimpager | Use Vim to see R documentation |
R_open_example | Use Vim to display R examples |
R_editor_w | Minimum width of R script buffer |
R_help_w | Desired width of R documentation buffer |
R_path | Directory where R is |
R_app, R_cmd | Names of R applications |
R_args | Arguments to pass to R |
R_start_libs | Objects for omni completion and syntax highlight |
Rout_more_colors | More syntax highlighting in R output |
R_hi_fun | Highlight R functions |
R_hi_fun_paren | Highlight R functions only if followed by a (
|
R_routnotab | Show output of R CMD BATCH in new window |
R_notmuxconf | Don't use a specially built Tmux config file |
R_rconsole_height | Number of lines of R Console |
R_rconsole_width | Number of columns of R Console |
R_min_editor_width | Minimum number of columns of editor after R start |
R_applescript | Use osascript in Mac OS X to run R.app |
RStudio_cmd | Run RStudio instead of R. |
R_listmethods | Do nvim.list.args() instead of args()
|
R_specialplot | Do nvim.plot() instead of plot()
|
R_paragraph_begin | Send paragraph from its beginning |
R_parenblock | Send lines until closing parenthesis |
R_bracketed_paste | Bracket R code in special escape sequences |
R_clear_console | Send <C-L> to clear R's console |
R_source_args | Arguments to R source() function |
R_latexcmd | Command to run on .tex files |
R_texerr | Show a summary of LaTeX errors after compilation |
R_sweaveargs | Arguments do Sweave()
|
R_rmd_environment | Environment in which to save evaluated rmd code |
R_rmarkdown_args | Further options to be passed to rmarkdown::render()
|
R_quarto_render_args | Options to be passed to quarto::quarto_render()
|
R_quarto_preview_args | Options to be passed to quarto::quarto_preview()
|
R_never_unmake_menu | Do not unmake the menu when switching buffers |
R_clear_line | Clear R Console line before sending a command |
R_editing_mode | The mode defined in your ~/.inputrc
|
R_pdfviewer | PDF application used to open PDF documents |
R_openpdf | Open PDF after processing rnoweb file |
R_openhtml | Open HTML after processing either Rrst or Rmd |
R_strict_rst | Code style for generated rst files |
R_insert_mode_cmds | Allow R commands in insert mode |
R_rmhidden | Remove hidden objects from R workspace |
R_source | Source additional scripts |
R_non_r_compl | Bibliography completion |
R_wait | Time to wait for nvimcom loading |
R_wait_reply | Time to wait for R reply |
R_nvim_wd | Start R in Vim's working directory |
R_after_start | Commands to be executed after R startup |
R_after_ob_open | Commands to be executed after the Object Browser opening |
R_debug | Support for debugging functions |
R_user_maps_only | Only user specified key bindings |
R_disable_cmds | List of commands to be disabled |
R_tmpdir | Where temporary files are created |
R_compldir | Where lists for omni completion are stored |
R_set_omnifunc | Should Nvim-R set the 'omnifunc'? |
R_fun_data_1 | What the data.frame to complete function arguments is |
R_fun_data_2 | Where the data.frame to complete function arguments is |
R_quarto_intel | Where the Quarto completion data is |
R_bib_compl | List of file types for bib completion |
R_remote_compldir | Mount point of remote cache directory |
Nvim-R-df-view | Options for visualizing a data.frame or matrix |
Nvim-R-SyncTeX | Options for SyncTeX |
By default, you have to start R manually with the command rf. If you want that R starts automatically when you load an R script while starting Vim, put in your |vimrc|:
let R_auto_start = 1
If you want that R starts automatically when you start editing an R script
even if Vim is already started, put in your vimrc
:
let R_auto_start = 2
See also: R_after_start
.
If you want to always start the Object Browser immediately after starting R,
put in your vimrc
:
let R_objbr_auto_start = 1
See also: R_after_ob_open
.
By default, R runs in a Vim buffer created with the command :term
,
and the <Esc>
key is mapped to stop the Terminal mode and go to Normal mode.
In Terminal mode, What you type is passed directly to R while in Normal mode
Vim's navigation commands work as usual (see |motion.txt|
).
If you need the <Esc>
key in R, for example if you want to use vi
, vim
or
nvim
within R Console, put in your vimrc
:
let R_esc_term = 0
Then, you will have to press the default <C-\><C-N>
to go from Terminal to
Normal mode.
Nvim-R sets the option "editor" to a function that makes the object to be
edited in a new tab when R_esc_term
= 1 (the default value).
Neovim does not close its built-in terminal emulator when the application
running in it quits, but Nvim-R does close it for you. If you rather prefer
that the terminal remains open after R quits, put in your vimrc
:
let R_close_term = 0
Neovim stops automatically scrolling the R Console if you move the cursor to any line that is not the last one. This emulates the behavior of other terminal emulator, but considering that (1) R only outputs something after we send a command to it, and (2) when we send a command to R, we want to see its output, Nvim-R will move the cursor to the last line of R Console before sending a command to it, forcing the auto scrolling of the terminal.
If you are using Neovim, Nvim-R will move the cursor to the end of R Console's
buffer before sending a command to force the scrolling R output, but you can
put the line below in your init.vim
to disable the auto scrolling of the
terminal:
let R_auto_scroll = 0
You may either use the package colorout (Unix only) to colorize R output or
let Neovim highlight the terminal contents as it was a .Rout file type. Two
advantages of colorout are the possibility of highlighting numbers close to
zero in a different color and the distinction between stdout and stderr. The
value of R_hl_term
(0 or 1) determines whether Neovim should syntax highlight
the R output, and its default value will be set to 0 if the package colorout
is loaded. If you prefer do not rely on the auto detection of colorout, you
should set the value of R_hl_term
in your vimrc
. Example:
let R_hl_term = 0
Right after starting R, Nvim-R will try to detect if either the value of R's
OutDec
option is ","
or the current R script sets the OutDec
option. If
you are using Neovim to syntax highlight R's output and it is not correctly
detecting R's OutDec
option, then, to get numbers correctly recognized, you
should put in your vimrc
:
let R_OutDec = ','
On Unix systems, BEFORE sending a command to R Console, if the terminal width
has changed, Vim will send to nvimcom the command options(width=X)
, where X is
the new terminal width. You can set the value of R_setwidth
to 0 to avoid the
width being set. Example:
let R_setwidth = 0
On Windows, the command is sent to R Console because it would crash R if sent through nvimcom.
If you have the option 'number' set in your vimrc
, Nvim-R will calculate the
number of columns available for R as the window width - 6. If you want a
different adjustment, you should set R_setwidth
as a negative value between
-1 and -16. Example:
let R_setwidth = -7
You can also set the value of R_setwidth
to 2
. In this case, nvimcom will
check the value of the environment variable COLUMNS
AFTER each command is
executed and if the environment variable exists, R's width option will be set
accordingly. This is the most precise way of setting the option "width", but
it has the disadvantage of setting it only after the command is executed. That
is, the width will be outdated for the first command executed after a change
in the number of columns of the R Console window.
Nvim-R sets the options winfixwidth
and winfixheight
in the window where R
runs. This prevents the window of being automatically resized in some
circumstances. It also sets the option 'nobuflisted'. You can set the value of
R_buffer_opts
to define what options should be set in the R Console buffer.
It is a list of Vim options separated by spaces. Example with its default
value:
let R_buffer_opts = "winfixwidth winfixheight nobuflisted"
If you do not want to run R in Vim's built in terminal emulator, you have to
install Tmux >= 2.0, and then put in your vimrc
:
let R_external_term = 1
Then, R will start in an external terminal emulator (useful if you use two monitors and want Vim and R separate from each other), and Tmux will be used to send commands from Vim to R.
Note: The options of this section are ignored on Mac OS X, where the command
open
is called to run the default application used to run shell scripts.
R will run in Vim's built-in terminal emulator, unless you set the
value of R_external_term
, which can be a numeric value (either 0
or 1
),
the name of the terminal emulator or the complete command to run the terminal
emulator. On Windows, the only valid value is 1
, which will make Nvim-R to run
Rgui.exe
, and not really a terminal emulator.
On Linux, the complete command for running the terminal is predefined for the following options:
1. foot
2. gnome-terminal,
3. konsole,
4. xfce4-terminal,
5. Eterm,
6. (u)rxvt,
7. aterm,
8. roxterm,
9. lxterminal
- xterm.
If the value of R_external_term
is 1, the plugin runs the first terminal
emulator that it finds from the above list. If your favorite terminal emulator
is not selected, you may define it in your vimrc
. Below are some examples of
how to set the value of R_external_term
:
let R_external_term = 1 " Run R in an external terminal (or Rgui.exe)
let R_external_term = 'foot' " Run R in in foot
If you are not satisfied with the way your terminal emulator is called by the
plugin, you may define in your vimrc
the variable R_external_term
as the
complete command to run the terminal. Examples:
let R_external_term = 'xterm -title R -e'
let R_external_term = 'tilix -a session-add-right -e'
let R_external_term = 'xfce4-terminal --icon=/path/to/icons/R.png --title=R -x'
let R_external_term = 'foot -a R -T R --login-shell --log-level error'
Please, look at the manual of your terminal emulator to know how to call it. The last argument must be the one which precedes the command to be executed.
The terminal error messages, if any, are shown as warning messages, unless you
put in your vimrc
:
let R_silent_term = 1
If R cannot find either make
or gcc
while trying to compile nvimcom, you
should add their directories to the beginning of the PATH
environment
variable in your vimrc
:
let $PATH = "C:\\rtools40\\mingw64\\bin;C:\\rtools40\\usr\\bin;" . $PATH
By default, Nvim-R will save the positions of R Console and Vim windows
when you quit R with the <LocalLeader>rq
command, and it will restore the
positions of the windows when you start R. If you do not like this behavior,
you can put in your vimrc
:
let R_save_win_pos = 0
let R_arrange_windows = 0
If you want R and GVim windows always in a specific arrangement, regardless of
their state when you have quit R for the last time, you should arrange them
in the way you want, quit R, change in your vimrc
only the value of
R_save_win_pos
and, finally, quit Vim.
The plugin sets $HOME
as the Windows register value for "Personal" "Shell
Folders" which is the same value set by R. However, if you have set $HOME
yourself with the intention of changing the default value of $HOME
assumed
by R, you will want to put in your vimrc
:
let R_set_home_env = 0
In Rnoweb files, a <
is replaced with <<>>=\n@
. To disable this feature,
put in your vimrc
:
let R_rnowebchunk = 0
Similarly, in Rmd files the grave accent (backtick) is replaced with chunk
delimiters unless you put in your vimrc
:
let R_rmdchunk = 0
You can also define a different shortcut for R_rmdchunk
. For example, to use
two backticks instead of one to trigger the completion of the chunk delimiter,
put in your vimrc
:
let R_rmdchunk = '``'
If R_rmdchunk = 2
(the default), in addition to creating an empty chunk
block, a single backtick will be converted in inline R delimiters if the cursor
is not at the beginning of the line.
While editing R code, _
is replaced with <-
. If you want to bind other
keys to be replaced by <-
, set the value of R_assign_map
in your
vimrc
, as in the example below which emulates RStudio behavior (may only
work on GVim or Neovim):
let R_assign_map = '<M-->'
Note: You can't map <C-=>
, as StatET does because in Vim only alphabetic
letters can be mapped in combination with the CTRL
key.
See also: https://github.com/jalvesaq/Nvim-R/issues/634
To completely disable this feature, put in your vimrc
:
let R_assign = 0
If you need to type many object names with underscores and still wnat to use _
as the trigger for the assign symbol, you may want to set the value R_assign
as 2. Then, you will have to type two _
to get them converted into <-
.
Alternatively, if the value of R_assign
is 3, the plugin will run the
following command in each buffer containing R code (R, Rnoweb, Rhelp, Rrst, and
Rmd):
iabb <buffer> _ <-
That is, the underscore will be replaced with the assign operator only if it is preceded by a space and followed by a non-word character.
By default, the Object Browser will be created at the right of the script
window, and with 40 columns. Valid values for the Object Browser placement are
the combination of either script
or console
and right
, left
, above
,
below
, separated by a comma. You can also simply choose RIGHT
, LEFT
,
TOP
or BOTTOM
to start the Object Browser as far as possible to the
indicated direction. Examples:
let R_objbr_place = 'script,right'
let R_objbr_place = 'console,left'
let R_objbr_place = 'LEFT'
let R_objbr_place = 'RIGHT'
The minimum width of the Object Browser window is 9 columns. You can change
the object browser's default width by setting the value of R_objbr_w
in your
vimrc
, as below:
let R_objbr_w = 30
If the Object Browser is being created bellow or at the top of the existing
window, it will be 10 lines high, unless you set its height in your vimrc
:
let R_objbr_h = 20
Below is an example of setup of some other options in the vimrc
that
control the behavior of the Object Browser:
let R_objbr_opendf = 1 " Show data.frames elements
let R_objbr_openlist = 0 " Show lists elements
let R_objbr_allnames = 0 " Show hidden objects
Objects whose names start with a "." are hidden by default. If you want them
displayed in the Object Browser, set the value of R_objbr_allnames
to 1
.
When a data.frame
appears in the Object Browser for the first time, its
elements are immediately displayed, but the elements of a list
are displayed
only if it is explicitly opened. The options R_objbr_opendf
and
R_objbr_openlist
control the initial status (either opened or closed) of,
respectively, data.frames
and lists
. The options are ignored for
data.frames
and lists
of libraries which are always started closed.
If you want to always start the Object Browser immediately after starting R, put
in your vimrc
:
let R_objbr_auto_start = 1
If you do not want to see R examples in a Vim buffer, put in your vimrc
:
let R_open_example = 0
If you do not want to see R documentation in a Vim buffer, put in your
vimrc
:
let R_nvimpager = 'no'
This option can only be set to "no" in the vimrc
. It will be automatically
changed to a suitable value if it is set to "no" after Vim startup.
If you want to see R documentation in Vim, but are not satisfied with the way it works, please, read the subsection below.
The plugin key bindings will remain active in the documentation buffer, and,
thus, you will be able to send commands to R as you do while editing an R
script. You can, for example, use <LocalLeader>rh
to jump to another R help
document.
The valid values of R_nvimpager
are:
-
vertical
: Split the window vertically if the editor width is large enough; otherwise, split the window horizontally and attempt to set the window height to at least 20 lines. This is the default. -
tab
: Show the help document in a new tab. If there is already a tab with an R help document tab, use it. This is the default ifR_external_term
= 1. -
horizontal
: Split the window horizontally. -
tabnew
: Show the help document in a new tab. -
no
: Do not show R documentation in Vim.
The window will be considered large enough if it has more columns than
R_editor_w
+ R_help_w
. These variables control the minimum width of the
editor window and the help window, and their default values are, respectively,
66 and 46. Thus, if you want to have more control over Vim's behavior while
opening R's documentations, you will want to set different values to some
variables in your vimrc
, as in the example:
let R_editor_w = 80
let R_editor_h = 60
Unless the value of R_nvimpager
is tabnew
, the buffer name will always be
R_doc
to force the reuse of the window when users jump from one help page to
another.
Vim will run the first R executable in the path. You can set an alternative
path to R in your vimrc
as in the examples:
let R_path = '/path/to/my/preferred/R/version/bin'
let R_path = "C:\\Program Files\\R\\R-3.3.1\\bin\\x64"
On Windows, Vim will try to find the R install path in the Windows Registry.
You can set the path to a different R version for specific R scripts in your
vimrc
. Example:
autocmd BufReadPre ~/old* let R_path='~/app/R-4.0.0/bin'
The R_path
variable can also be prefixed to the PATH
environment variable.
So, it can include more than one directory separated by a ;
on Windows or a
:
on other systems. This is specially important to include the path to RTools
bin
directories on Windows. Example:
let R_path = 'C:\rtools40\mingw64\bin;C:\rtools40\usr\bin;C:\Program Files\R\R-4.0.1\bin\x64'
By default R_cmd
is "R"
(but it might be the same as R_app
) and will
be used to run some scripts in the background, such as:
R CMD build nvimcom
R CMD install nvimcom
R CMD BATCH current_script.R
If it is necessary to call a different application to run the above commands
in your system, you should set the value of R_cmd
in your vimrc
.
By default the value of R_app
is "R"
on Unix systems (such as Linux and Mac
OS X). On Windows, it is Rterm.exe
if R is going to run in a Vim buffer and
"Rgui.exe"
otherwise. Nvim-R cannot send messages to Rterm.exe
in an
external cmd
window. If your R binary has a different name (for example, if it
is called by a custom script), you should set the value of R_app
in your
vimrc
(and, perhaps, R_cmd
too). Example:
let R_app = 'radian'
let R_cmd = 'R'
Set this option in your vimrc
if you want to pass command line arguments to
R at the startup. The value of this variable must be a List
. Example:
let R_args = ['--no-save', '--quiet']
On Linux, there is no default value for R_args
. On Windows, the default
value is ['--sdi']
, but you may change it to ['--mdi']
if you do not like
the SDI style of the graphical user interface.
The list of functions to be highlighted and the list of objects for omni
completion are built dynamically as the libraries are loaded by R. If R is
running, only the names of objects in .GlobalEnv and in loaded libraries are
completed. If R is not running, only objects of libraries listed in
R_start_libs
and as the first argument of either
library()
and require()
commands in the current buffer will have their names
completed. However, you can set the value of R_start_libs
if you want that the functions and objects of specific packages are respectively
highlighted and available for omni completion even if R is not running yet. By
default, only the functions of vanilla R are always highlighted. Below is the
default value of R_start_libs
:
let R_start_libs = 'base,stats,graphics,grDevices,utils,methods'
By default, the R commands in .Rout files are highlighted with the color of comments, and only the output of commands has some of its elements highlighted (numbers, strings, index of vectors, warnings and errors).
If you prefer that R commands in the R output are highlighted as they are in R
scripts, put the following in your vimrc
:
let Rout_more_colors = 1
When syntax highlighting .Rout files, Nvim-R considers "> " as the prompt string
and "+ " as the continuation string. If you have defined different prompt and
continuation strings in your ~/.Rprofile
, Nvim-R will try to get them from R,
but if they include special characters, you may have to define them in your
vimrc
too to avoid errors and get them properly highlighted. For example, if
you have in your ~/.Rprofile
options(prompt = '\u1b[34m»\u1b[0m ')
you should put in your vimrc
:
let Rout_prompt_str = '»'
By default, Nvim-R highlights the names of R functions even if they are not
followed by a parenthesis. If you prefer to highlight R functions only if
the (
is typed, put in your vimrc
:
let R_hi_fun_paren = 1
Notes:
-
The syntax highlighting is slower when
R_hi_fun_paren
is 1, and, depending on your system configuration, the slowness might be noticeable. -
If you have too many loaded packages Vim may be unable to load the list of functions for syntax highlight.
-
Nvim-R does not control the syntax highlighting of functions when
nvim-treesitter
is enabled to highlight code on Neovim.
By default, functions from .GlobalEnv
and other environments in the
search()
path whose names do not start with "package:"
are immediately
highlighted after being created in the R workspace if R_set_omnifunc
is not
empty, the Object Browser is open, or cmp-nvim-r
is installed.
Functions from environments in the search path are highlighted as functions
from packages, but in Neovim (not in Vim) you can set a different highlight
command for them in your vimrc
, as in the example below:
hi rGlobEnvFun ctermfg=117 guifg=#87d7ff cterm=italic gui=italic
If you prefer to completely disable the syntax highlighting of R functions by
Nvim-R put in your vimrc
:
let R_hi_fun = 0
After the command <LocalLeader>ao
, Vim will save the current buffer if it
has any pending changes, run R CMD BATCH --no-restore --no-save
on the
current file and show the resulting .Rout file in a new tab. If you prefer
that the file is open in a new split window, put in your vimrc
:
let R_routnotab = 1
If Vim is running R in an external terminal emulator, R will run in a Tmux
session with a specially built Tmux configuration file. If you want to use
your own ~/.tmux.conf, put in your vimrc
:
let R_notmuxconf = 1
If you opted for using your own configuration file, the plugin will write a minimum configuration which will set the value of four environment variables required for the communication with R and then source your own configuration file (~/.tmux.conf).
When starting R, Vim's buffer is split vertically if its width is larger than:
R_min_editor_width + R_rconsole_width + 1 + (&number * &numberwidth)
That is, if it is large enough to guarantee that both the script and the R
windows will have at least the desired number of columns even if 'number' is
set. The default value of both R_min_editor_width
and R_rconsole_width
is
80. If you prefer the window is always split vertically, set these two options
with lower values in your vimrc
. Example:
let R_rconsole_width = 57
let R_min_editor_width = 18
You can also set a R_rconsole_width
relative to current Vim window width.
For example, if you want to split the available horizontal space evenly
between Vim and R, put in your vimrc
:
let R_rconsole_width = winwidth(0) / 2
autocmd VimResized * let R_rconsole_width = winwidth(0) / 2
If you always prefer a horizontal split, set the value of R_rconsole_width
to 0:
let R_rconsole_width = 0
For a horizontal split, you can set the number of lines of the R window:
let R_rconsole_height = 15
You should set 'nosplitright' if you wanted the R Console on the left side, and 'nosplitbelow' if you wanted it above the R script.
Note: If running R in a Neovim buffer, the number of lines and columns will
automatically change if you switch between horizontal and vertical splits (see
CTRL-W_K
and CTRL-W_H
). You may request Neovim to try to keep the minimum
width and height of a specific window by setting the options 'winwidth' and
'winheight'. So, if the window is split horizontally and you want a small R
Console window, you should set a large value for 'winheight' in the script
window.
If you are on Mac OS X and want to use the R.app graphical application, put in
your vimrc
:
let R_external_term = 1
let R_applescript = 1
If you want to run RStudio instead of R set in your vimrc
the value of
RStudio_cmd
to the complete path of the RStudio_cmd
binary. Example:
let R_external_term = 1
let RStudio_cmd = 'C:\Program Files\RStudio\bin\rstudio'
Note: You must manually run a successful comand in RStudio Console before
sending code from Vim to RStudio. The command might be something as simple as
the number 1
.
The R function args()
lists the arguments of a function, but not the
arguments of its methods. If you want that the plugin calls the function
nvim.list.args()
after <LocalLeader>ra
, you have to add to your vimrc
:
let R_listmethods = 1
By default, R makes a scatter plot of numeric vectors. The function
nvim.plot()
do both a histogram and a box plot. The function can be called by
the plugin after <LocalLeader>rg
if you put the following line in your
vimrc
:
let R_specialplot = 1
By default, when you press <LocalLeader>pp
Nvim-R sends all contiguous lines
to R, that is all lines above and below the current one that are not separated
by an empty line. If you prefer that only lines from the cursor position to the
end of the paragraph are sent, put in your vimrc
:
let R_paragraph_begin = 0
If a line has an opening parenthesis, all lines up to the closing parenthesis
are sent to R when you send a line of code to R. If you prefer to send the
lines one by one, put in your vimrc
:
let R_parenblock = 0
Bracketed paste mode will bracket R code in special escape sequences when it
is being sent to R so that R can tell the differences between stuff that you
type directly to the console and stuff that you send. It is particularly
useful when you are using a version of R which is compiled against readline
7.0+ or when rice console is used. To enable it, put in your vimrc
:
let R_bracketed_paste = 1
Some versions of R's console interpret <C-L>
as a command to clear the console
while others have no command to clear the console. You should set the value of
R_clear_console
as 0
if you see ^L
printed in the R's console after
<LocalLeader>rm
:
let R_clear_console = 0
When you send multiple lines of code to R (a selection of lines, a paragraph,
code between two marks or an R chunk of code), Nvim-R saves the lines in a
temporary file and, then, sends to R a command which calls base::source()
to
run the commands from the temporary file.
By default, R's source()
is called with the arguments print.eval=TRUE
and
spaced=FALSE
. The argument local=parent.frame()
is passed to source()
too because it is run inside another function. But you can either add or
change the arguments passed to it. Examples:
let R_source_args = 'echo = TRUE'
let R_source_args = 'print.eval = FALSE, echo = TRUE, spaced = TRUE'
The option R_commented_lines
was dropped because it unduly removed lines from
multi-line raw strings if they included a hashtag. See:
https://github.com/jalvesaq/Nvim-R/issues/743
To produce a pdf document from the .tex file generated by either Sweave()
or
knit()
command, Nvim-R calls:
latexmk -pdf -pdflatex="xelatex %O -file-line-error -interaction=nonstopmode -synctex=1 %S"
If xelatex
is not installed, it will be replaced with pdflatex
in the
above command. If latexmk
is not installed, Nvim-R will call either
xelatex
or pdflatex
directly.
You can set the value R_latexcmd
to change this behavior. R_latexcmd
is a
list: its first element is the command to be executed and the remaining
elements are arguments to be passed to the command. Examples:
let R_latexcmd = ['pdflatex']
let R_latexcmd = ['xelatex']
let R_latexcmd = ['latexmk', '-pdf', '-pdflatex="xelatex %O -synctex=1 %S"']
The elements of R_latexcmd
may contain double quotes (as in the last example
above), but not single quotes, because Nvim-R will use single quotes to
separate them in an R's c()
command.
If you want to pass arguments to the Sweave()
function, set the value of the
R_sweaveargs
variable.
If the value of R_texerr
is 1
, nvmimcom will output to R Console LaTeX
errors and warnings produced by the compilation of the .tex document into
.pdf. So, you do not have to scroll the R Console seeking for these messages.
However, if Nvim-R cannot not find the LaTeX log file because it is not saved
in the same directory as the Rnoweb, you should set the value of
R_latex_build_dir
. Example:
let R_latex_build_dir = 'build'
See also R_bib_compl
.
When rendering an Rmd file, the code can be evaluated (and saved) in a
specified environment. The default value is .GlobalEnv
which makes the
objects stored in the Rmd file available on the R console. If you do not want
the objects stored in the Rmd file to be available in the global environment,
you can set
let R_rmd_environment = 'new.env()'
Other options to be passed to rmarkdown::render()
might be defined with
R_rmarkdown_args
, as in the example:
let R_rmarkdown_args = 'output_dir = "output", clean = FALSE'
If you want to send the commands quarto::quarto_render()
and
quarto::quarto_preview()
to R with additional arguments, you should define
the values of R_quarto_render_args
and R_quarto_preview_args
in your
vimrc
, as in the examples:
let R_quarto_render_args = ', pandoc_args = c("-F", "apafix.py")'
let R_quarto_preview_args = ', browse = FALSE'
Use this option if you want that the "R" menu item in GVim is not deleted when you change from one buffer to another, for example, when going from a .R file to a .txt one:
let R_never_unmake_menu = 1
When this option is enabled all menu items are created regardless of the file type.
When one types <C-a>
in the R Console the cursor goes to the beginning of the
line and when one types <C-k>
the characters to the right of the cursor are
deleted. This is useful to avoid characters left on the R Console being mixed
with commands sent by Vim. Nvim-R will add <C-a><C-k>
to every command if you
put in your vimrc
:
let R_clear_line = 1
Nvim-R reads your ~/.inputrc
and, if it finds the string "set editing-mode
vi" it will send to R 0Da instead of <C-a><C-k>
. If Nvim-R fails to
detect that R is running in vi editing mode, you have to put this line in your
vimrc
:
let R_editing_mode = "vi"
This might produce a beep when sending commands, and you may want to disable
the audible bell only for R by putting in your ~/.inputrc
:
$if R
set bell-style none
$else
set bell-style audible
$endif
Note: You can't control the bell on Windows; it is hardcoded to run in Rterm and to not run in Rgui.
The plugin can automatically open the pdf file generated by pdflatex, after
either Sweave()
or knit()
. This behavior is controlled by the variable
R_openpdf
whose value may be 0 (do not open the pdf), 1 (open only
the first time that pdflatex is called) or a number higher than 1 (always
open the pdf). For example, if you want that the pdf application is started
automatically but do not want the terminal (or GVim) losing focus every time
that you generate the pdf, you should put in put in your vimrc
:
let R_openpdf = 1
If you use Linux or other Unix and eventually use the system console (without
the X server) you may want to put in your vimrc
:
if $DISPLAY == "" && $WAYLAND_DISPLAY == ""
let R_openpdf = 0
endif
The default value of R_openpdf
is 1 on Mac OS X and 2 on Windows. On Linux, it
is 2 on the X Server and on Sway Window Manager and 1 on other Wayland
compositors.
On Windows, Nvim-R will call Sumatra to open the PDF, and, on Mac OS X, it
will call Skim. On Linux, you can change the value of R_pdfviewer
in your
vimrc
to define what PDF viewer will be called. Valid values are "zathura"
(default, and the one best integrated with Nvim-R), "evince" and "okular".
On Linux, if running on the X server (not on Wayland), the application
wmctrl
is required to raise both the PDF viewer and Vim windows. If using
Gnome Shell on Wayland, the extension "Activate Window By Title" is required
(https://extensions.gnome.org/extension/5021/activate-window-by-title/).
If editing an Rmd file, you can produce the html result with <LocalLeader>kr
or <LocalLeader>kh
(it may also work with other file types). The html file
will be automatically opened if you put the following in your vimrc
:
let R_openhtml = 1
The meanings of different values of R_openhtml
are:
0
: Never open the html.
1
: Always open the html.
The browser application called by Nvim-R is whatever is returned by the R
command getOption("browser")
, unless it is NULL. In this case, Nvim-R will
call open
on both Windows and Mac OS X, and xdg-open
on Linux.
Most browser will open a new tab each time they are called instead of refreshing
a document that is already open. If you rather prefer that Nvim-R never tries to
open the web browser, put in your vimrc
:
let R_openhtml = 0
For Quarto documents, the available key bindings are <LocalLeader>qr
(render
document), <LocalLeader>qp
(preview document), and <LocalLeader>qs
(stop
previewing). The command <LocalLeader>kr
achieves basically the same result of
<LocalLeader>kr
. The difference is that the generated document is open after
<LocalLeader>kr
, and <LocalLeader>qr
allows Quarto specific
options (see R_quarto_render_args
).
By default, Nvim-R sends the command render_rst(strict=TRUE)
to R
before using R's knit()
function to convert an Rrst file into an rst one. If
you prefer the non strict rst code, put the following in your vimrc
:
let R_strict_rst = 0
You can also set the value of R_rst2pdfpath
(the path to rst2pdf
application), R_rrstcompiler
(the compiler argument to be passed to R
function knit2pdf
), and R_rst2pdfargs
(further arguments to be passed
to R function knit2pdf
).
Nvim-R commands are enabled for Normal mode, but most of them can also be
enabled in Insert mode. However, depending on your <LocalLeader>
, this can
make it very difficult to write R packages or Sweave files. For example, if
<LocalLeader>
is set to the \
character, typing \dQuote
in a
.Rd file tries to send the command!
If you want to enable commands in Insert mode, add the following to your
vimrc
:
let R_insert_mode_cmds = 1
Hidden objects are removed from R workspace when you do <LocalLeader>rm
. If
you prefer to remove only visible objects, put in your vimrc
:
let g:R_rmhidden = 0
After removing the objects, Nvim-R will also send CTRL-L to the R Console to
clear the screen. If you have set vi mode in your ~/.inputrc
you might also
want to set CTRL-L to clear the screen, as explained at
https://unix.stackexchange.com/questions/104094/is-there-any-way-to-enable-ctrll-to-clear-screen-when-set-o-vi-is-set
This variable should contain a comma separated list of Vim scripts to be
sourced by Nvim-R. These scripts may provide additional
functionality and/or change the behavior of Nvim-R. If you have such
scripts, put in your vimrc
:
let R_source = '~/path/to/MyScript.vim,/path/to/AnotherScript.vim'
Currently, there is only one script known to extend Nvim-R features - support for the devtools R package: https://github.com/mllg/vim-devtools-plugin
The omni completion of bibliographic data from bib files requires Python 3 and the PyBTeX library for Python 3.
For Rnoweb documents, omni completion of citation keys gathers data from
.bib
files in the same directory of the current Rnoweb document, and the
completion works only if a pattern similar to "\cite{" precedes the cursor
(see R_cite_pattern
). Some of the most commonly used LaTeX commands are also
completed. The completion of the argument for both \ref{}
and \pageref{}
includes both the label of R chunks where the option fig.cap
was found
prefixed with fig:
and the string attributed to the argument label
in the
R code, but only if they begin with the substring "tab:".
If the reference includes the field "file", you can open this file by typing
<LocalLeader>od
in Normal mode with the cursor over the citation key.
For either RMarkdown or Quarto documents it is recommended to install zotcite and cmp-zotcite for completing citation keys directly from Zotero database.
If zotcite is not installed, Nvim-R will do omni completion of bibliographic
citation keys from .bib
files, requiring Python 3 and the PyBTeX library for
Python 3 to work. Then, Nvim-R will look for bibliographic data in any .bib
file listed in the bibliography
field of the YAML header. If the
bibliography
field is not defined, it will use all .bib
files that are in
the same directory of the RMarkdown document as bibliography sources. The list
of .bib
files is updated whenever the buffer is saved.
If the reference includes the field "file", you can open this file by typing
<LocalLeader>od
in Normal mode with the cursor over the citation key.
If you include Python chunks in your Rmd document, you should put the lines
below in your vimrc
to get them highlighted:
let g:markdown_fenced_languages = ['r', 'python']
let g:rmd_fenced_languages = ['r', 'python']
Lines of Python code are sent to R Console as arguments to
reticulate::py_run_string()
To disable the completion of non R code in Rmd and Rnoweb files, and use the
omni completion provided by another plugin, put in your vimrc
:
let R_non_r_compl = 0
Then, Nvim-R may use another function to complete non R code, such as the ones from vim-pandoc or LaTeX-Box
If you want a different function for completion of non R code, you should not
set the value 'omnifunc' in your vimrc
because you would lose the completion
of R objects. It is better to use an autocmd
to set the value of the buffer
the variable b:rplugin_non_r_omnifunc
. Example:
autocmd FileType rmd let b:rplugin_non_r_omnifunc = "pandoc#completion#Complete"
Note: On Windows, Nvim-R's bibliographic completion works only with ascii
letters. See also R_bib_compl
.
Nvim-R asynchronously waits 60 seconds for the nvimcom package to be loaded
during R startup. If 60 seconds are not enough to your R startup, then set a
higher value for the variable in your vimrc
. Example:
let R_wait = 100
By default Nvim-R waits 2 seconds for R to reply after a request for omni
completion is issued. You can set the amount of time Nvim-R waits (in seconds)
in your vimrc
. Example:
let R_wait_reply = 5
When you are editing an R file (.R, .Rnw, .Rd, .Rmd, .Rrst, or .qmd) and start
R, the R package nvimcom runs the command setwd()
with the directory of the
file being edited as argument, that is, the R working directory becomes the same
directory of the R file. If you want R's working directory to be the same as
Vim's working directory, put in your vimrc
:
let R_nvim_wd = 1
This option is useful only for those who did not enable 'autochdir'.
If you prefer that Nvim-R does not set the working directory in any way, put
in vimrc
:
let R_nvim_wd = -1
If you want the execution of Vim, R, or external commands right after R startup,
set the value of R_after_start
in your vimrc
. The R_after_start
variable
must be a list of strings. Strings representing Vim commands must start with
:
, R commands must be prefixed with R:
, and external commands must be
prefixed with !
.
You can put commands in your ~/.Rprofile
that will be run only if R was
started by Nvim-R as in the example below:
if (Sys.getenv("NVIMR_TMPDIR") == "")
cat("~/Rprofile: R was called by Nvim-R\n", file = stderr())
However, if for any reason you ~/.Rprofile
is not being sourced, you can
include in R_after_start
R commands that should be executed during R startup
(more precisely, during nvimcom
loading). Example:
let R_after_start = ['R: cat("R_after_start: R was called by Nvim-R\n", file = stderr())']
Note: The loading of nvimcom
will fail if the command to be executed is
invalid. In the example above, we have had to use \n
to indicate a new line.
For an example of Vim command, if you want that the R script window is hidden
right after R startup, put in your vimrc
:
let R_after_start = [':hide']
Nvim-R stores the environment variable $WINDOWID
of the terminal where R is
running as $RCONSOLE
. Thus, if you are running R in a external terminal
emulator on the X server (not on Wayland) on Linux, ~/bin
is in your path, and
you want to resize and change the positions of the terminals containing Vim and
R, you may create a script ~/bin/after_R_start
similar to the following:
#!/bin/sh
wmctrl -i -r $RCONSOLE -e 0,0,200,1200,800
wmctrl -i -r $WINDOWID -e 0,300,40,1200,800
wmctrl -i -r $WINDOWID -b remove,maximized_vert,maximized_horz
Then, make the script executable, and put in your vimrc
:
let R_external_term = 1 let R_after_start = ['!after_R_start']
Similarly, on Mac OS X, the script below (developed by songcai) will bring the focus to Vim terminal window:
#!/usr/bin/env osascript
--Raise the Terminal window containing name ".R".
tell application "Terminal"
set index of window 1 where name contains ".R" to 1
delay 0.05
activate window 1
end tell
--Click the title bar of the raised window to bring focus to it.
tell application "System Events"
tell process "Terminal"
click menu item (name of window 1) of menu of menu bar item "Window" of menu bar 1
end tell
end tell
If you want that Nvim-R executes Vim commands right after the Object Browser is
open, set the value of R_after_ob_open
as a list of commands. Example:
let R_after_ob_open = [':tabnew %']
Put the line below in your vimrc
if do not want that the cursor jumps to the
line being debugged (when by browser()
is run). Highlighting of the line being
debugged will also be disabled.
let R_debug = 0
Nvim-R puts the cursor in the R Console when the debugging starts. If you do
not want this, put this in your vimrc
:
let R_dbg_jump = 0
The highlighted line incrementally moves down the buffer with code execution and with long scripts it may stay at the bottom of the window as you debug. You can hold the highlighted line in the middle of the window with
let R_debug_center = 1
The Nvim-R sets many default key bindings. The user can set custom
key bindings (Nvim-R-key-bindings). If you wish Nvim-R
to only use those key-bindings specified by the user, put in your vimrc
:
let R_user_maps_only = 1
If you want to disable only some of Nvim-R commands, create a Vim list with
their key bindings names in your vimrc
. The complete list of key bindings
names is shown at the Custom key bindings section (Nvim-R-key-bindings).
Below is an example on how to disable the commands that sends setwd()
and
dput()
to R Console:
let R_disable_cmds = ['RSetwd', 'RDputObj']
If you want to disable Nvim-R for a specific file type, create the variable
R_filetypes
with a list of file types that should be supported. Example:
let R_filetypes = ['r', 'rmd', 'rrst', 'rnoweb', 'quarto', 'rhelp']
If the variable R_filetypes
does not exist, all file types from the above
list will be supported.
You can change the directories where temporary files are created and
stored by setting in your vimrc
the values of R_tmpdir
and
R_compldir
, as in the example below:
let R_tmpdir = '/dev/shm/R_tmp_dir'
let R_compldir = '~/.cache/Nvim-R'
The default paths of these directories depend on the operating system. If you want to know what they are, while editing an R file, do in Normal mode:
:echo g:rplugin.tmpdir
:echo g:rplugin.compldir
There are two ways of getting automatic completion of R objects names while you
type: using Nvim-R's built-in completion system (as a source for nvim-cmp
) and
using a language server. See:
https://github.com/jalvesaq/cmp-nvim-r https://github.com/REditorSupport/languageserver
The advantage of Nvim-R's built-in system is the ability to complete objects
of the R's workspace (.GlobalEnv
), including column names of data.frames.
Note: If you are using the languageserver
package, you should disable its omni
completion feature in your ~/.Rprofile
to get completions from
cmp-nvim-r
:
options(languageserver.server_capabilities =
list(completionProvider = FALSE,
completionItemResolve = FALSE))
If you prefer to get completions from the language server,
cmp-nvim-r
should not be installed,
and you should set both R_set_omnifunc
as an empty list in your vimrc
:
let R_set_omnifunc = []
let R_auto_omni = []
If cmp-nvim-r
is not installed, you still can define in your vimrc
the list
of file types supported by Nvim-R that should have the traditional Vim's omni
completion enabled. Example:
let R_set_omnifunc = ["r", "rmd", "quarto", "rnoweb", "rhelp", "rrst"]
While completing function arguments, Nvim-R may include column names from the
data.frame passed as the first argument, and you may set in your vimrc
the
list of functions that might benefit from this kind of completion. The example
below sets R_fun_data_1
to its default value:
let R_fun_data_1 = ['select', 'rename', 'mutate', 'filter']
Nvim-R can also include column names from a data.frame passed as the first argument of the parent function. For example, if you were typing
with(my_data_frame, lm(
and, then, trigger omni completion, the column names of my_data_frame
would be
included in the completion menu. By default, only the function aes
(if passed
as argument for ggplot
) and the functions lm
, glm
or lmer
(if passed as
argument for with
) will have column names of the first argument of the parent
function included in the completion menu. You have to set the value of
R_fun_data_2
in your vimrc
to include more functions. R_fun_data_2
is a
dictionary with parent functions as keys. The value of each key is a list of
functions that are expected to be nested in the parent function. If the name of
the nested function is *
, it will match any name. Example:
let R_fun_data_2 = {'ggplot': ['aes'], 'with': ['*']}
Note: The algorithm for finding the first argument of the parent function is
very simple and would wrongly recognize data
as the name of the data.frame
in the following code:
ggplot(data = my_data_frame, mapping = aes(
Nvim-R receives the list of objects for omni completion from the nvimrserver
job running in the background. If the list is too big to be transmitted through
nvimrserver's stdout
, the completion is aborted.
If editing Quarto documents, Nvim-R will try to find the file
yaml-intelligence-resources.json
which is part of quarto
application and has
all necessary information for completion of valid YAML options in an Quarto
document. If Nvim-R fails to find the file, you can set the value of
R_quarto_intel
in your vimrc
. Example:
let R_quarto_intel = '~/Downloads/quarto-1.1.251/share/editor/tools/yaml/yaml-intelligence-resources.json'
Omni completion in Rnoweb files will include results from bib files entries
(requiring Python 3 and python3-pybtex): required for omni completion of
citation keys (following R_cite_pattern
) in Rnoweb documents.
let R_bib_compl = ['rnoweb', 'rmd', 'quarto']
However, there are many alternative plugins for completing bib keys that work better than Nvim-R. Examples:
-
zotcite
withcmp-zotice
(for Markdown, Rmd and Quarto) -
VimTeX
(for Rnoweb) -
Either
cmp-pandoc-references
orcmp-pandoc.nvim
source fornvim-cmp
See Remote Access.
You can see data.frames and matrices in external applications with
<LocalLeader>rv
. By default, Nvim-R will generate a tsv
file from the
data.frame
or matrix
and display it in a new tab. But you can change this
by setting the value of R_csv_app
which must be a string.
If R_csv_app
begins with "terminal:", Nvim-R will open a new tab with the
application running in a terminal emulator. For example, if you want to use
Visidata to see tabular data, put in your vimrc
:
let R_csv_app = 'terminal:vd'
If you are running Vim within Tmux, you may prefer:
let R_csv_app = 'tmux new-window vd'
If R_csv_app
begins with ":", Nvim-R will append the name of the tsv file
and :execute
the command. Example:
let R_csv_app = ':vsplit'
You may also include "%s" in R_csv_app
to indicate the position of the tsv
file name in the command to be executed. Example using the toggleterm.nvim
plugin which requires the whole command within quotes:
let R_csv_app = ':TermExec cmd="vd %s"'
You may also try to see the table in a graphical viewer such as LibreOffice Calc:
let R_csv_app = 'localc'
let R_csv_app = 'c:/Program Files (x86)/LibreOffice 4/program/scalc.exe'
On Windows, R_csv_app
works only in GVim, not in Neovim.
If the default field delimiter causes problems in your case, you can change it
in your vimrc
. Valid values are "\t"
, ";"
and ","
. Example:
let R_csv_delim = ','
There is also the option of configuring Nvim-R to run an R command to display the data. Examples:
let R_df_viewer = "relimp::showData(%s, font = 'Courier 14')"
The value of R_df_viewer
is a string and the substring %s
is replaced by the
name of the object under the cursor.
SyncTeX is a communication system used by some PDF viewers and by some text editors which allow users to jump from a specific line in the text editor to the corresponding line in the PDF viewer and vice-versa. Nvim-R has support for SyncTeX in five applications:
Linux: Zathura, Evince and Okular OS X: Skim Windows: SumatraPDF
On Linux, if running on the X server (not on Wayland), the application
wmctrl
is required to raise both the PDF viewer and Vim windows.
To completely disable SyncTeX support, put in your vimrc
:
let R_synctex = 0
You do not have to do anything special in your Rnoweb document, if you are using the knitr package, and are editing single file Rnoweb documents. Otherwise, keep reading...
If you use Sweave()
rather than knit()
, you must put in your Rnoweb
document:
\SweaveOpts{concordance=TRUE}
If you work with a master document and child subdocuments, each child subdocument (TeX and Rnoweb alike) should include the following line:
% !Rnw root = master.Rnw
where master.Rnw
must be replaced with the name of the actual master
document.
Note: The knitr package ( as of version 1.7) had at least two limitations:
-
It had no SyncTeX support for child documents. The correspondence data point to lines right below child chunks in the master document and not to somewhere in the child documents themselves. See: https://github.com/yihui/knitr/issues/225
-
It only started registering the concordance after the first chunk. So, it is recommended that you put the first chunk of R code just after the
\begin{document}
command.
If running Gnome Shell on Wayland, you have to install the extension "Activate
Window by Title" and set the title of your terminal emulator in your vimrc
in order to have the terminal window raised on SyncTeX backward events.
Example:
let R_term_title = 'Terminal'