An open API service indexing awesome lists of open source software.

https://github.com/mllg/vim-devtools-plugin

Extension for vim-r-plugin to support the devtools package
https://github.com/mllg/vim-devtools-plugin

Last synced: about 1 month ago
JSON representation

Extension for vim-r-plugin to support the devtools package

Awesome Lists containing this project

README

        

# vim-devtools-plugin

Extension for the vim plugins [Vim-R-Plugin](https://github.com/jcfaria/Vim-R-plugin) and [Nvim-r](https://github.com/jalvesaq/Nvim-R) to support the [devtools R package](https://github.com/hadley/devtools).

## Installation
Use your favourite bundle manager to install this script, e.g.:
```vim
" Vundle
Plugin 'mllg/vim-devtools-plugin'

" Neobundle with lazy load
NeoBundleLazy 'mllg/vim-devtools-plugin',
\ {'autoload' : {'filetypes' : ['r','rmd','rnoweb']}}

" dein with lazy load
call dein#add('mllg/vim-devtools-plugin', {'on_ft' : ['r', 'rmd', 'rdoc', 'rnoweb']})

" Vim-Plug with lazy load
Plug 'mllg/vim-devtools-plugin', { 'for': ['r', 'rmd', 'rnoweb']}

" packer
use { 'mllg/vim-devtools-plugin', ft = {'r', 'rmd', 'rnoweb'}}
```

## Available commands

* `RInstallPackage `: Runs `devtools::install`.
* `RLoadPackage `: Runs `devtools::load_all`.
* `RUnloadPackage `: Runs `devtools::unload`.
* `RBuildPackage `: Runs `devtools::build`.
* `RCheckPackage `: Runs `devtools::check`.
* `RClean `: Runs `devtools::clean_dll`
* `RTestPackage `: Runs `devtools::test` using specified filter (default `''`).
* `RDocumentPackage `: Runs `devtools::document`
* `RMake `: Runs `devtools::document`, then `devtools::install`.
* `RSetupTest `: Loads "testthat" and invisibly sources all files matching pattern `^helper` in the test directory.
* `RSourceFile `: Sources the given file. If argument is omitted, either the master file (if set, see below) or the current buffer gets sourced.
* `RBuildPackgeTags `: Builds a tag file for the package and stores it in `g:devtools_rtags_dir` (default is "~/.rtags"). All tag files in this directory will automatically added to &tags for file types `r`, `rnoweb` and `rmd`.
* `RUsage `: Loads the package and calls `codetools::checkUsagePackage()`. Reported problems are send to the quickfix window.
* `RSetMaster `: Declare as the master file. Used in `:RSourceFile`. If is omitted, the current buffer is declared as master.
Note that this choice is not persistent between vim sessions.

The DESCRIPTION file is searched in `` and all its parents.
Default for `` is the directory of the current buffer.

The command `RTestFile` has been removed to simplify command completion with the much more frequently used `RTestFile`.
If you liked it, you can restore it by defining the command in your `.vimrc`:
```vim
command! -nargs=0 RTestFile :call devtools#test_file()
```

If you do not want any of these commands to be defined, set the option `devtools_commands`:
```vim
let g:devtools_commands = 0
```

## Support for FZF

If you are a user of [FZF](https://github.com/junegunn/fzf.vim), you can grep your R history file with the following setup:

### Make R history persistent across sessions

Put the following code in your `.Rprofile`, preferably inside the `.First` function:

```r
if (interactive()) {
history_file = normalizePath("~/.Rhistory", mustWork = FALSE)
ok = try(utils::loadhistory(history_file))
if (inherits(ok, "try-error")) {
message("History could not be loaded: ", history_file)
} else {
message("Loaded history: ", history_file)
.Last <<- function() try(utils::savehistory(history_file))
}
}
```

### Create new command
```vim
function! s:fzf_r_history()
let l:history_file = expand('~/.Rhistory')
call g:devtools#send_cmd('utils::savehistory("' . l:history_file . '")')
call fzf#run({
\ 'source': 'cat ' . l:history_file . ' | grep -v "# \\[history skip\\]$" | uniq',
\ 'sink' : g:SendCmdToR,
\ 'options': '--no-sort --tac',
\ 'down' : '40%' })
endfunction

command! RHistory call s:fzf_r_history()
```
Map to a key as you find appropiate.