Skip to content

Commit b76fe5e

Browse files
author
emzap79
committed
add cleaned-up snippets for R
1 parent 2626c45 commit b76fe5e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

UltiSnips/r.snippets

+33
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
11
priority -50
22

3+
global !p
4+
import os
5+
from vimsnippets import complete
6+
7+
FIELD_TYPES = [
8+
'character',
9+
'data.frame',
10+
'integer',
11+
'list',
12+
'logical',
13+
'matrix',
14+
'numeric',
15+
'vector']
16+
endglobal
17+
318
snippet #! "Hashbang for Rscript (#!)" b
419
#!/usr/bin/env Rscript
520
endsnippet
621

22+
snippet setwd "Set workingdir" b
23+
setwd("${1:`!p snip.rv = os.getcwd()`}")
24+
endsnippet
25+
26+
snippet as "Apply type on variable" w
27+
as.$1`!p snip.rv = complete(t[1], FIELD_TYPES)`(${2}${VISUAL})
28+
endsnippet
29+
30+
snippet is "Test type on variable" w
31+
is.$1`!p snip.rv = complete(t[1], FIELD_TYPES)`(${2}${VISUAL})
32+
endsnippet
33+
34+
snippet dl "Download and install a package" b
35+
download.file("${1:${VISUAL:url to package}}", destfile = "${2:${1/.*\/(\S*)$/(?1:$1)/ga}}")
36+
install.packages("$2", type = "source", repos = NULL)
37+
library("${3:${2/^(\w+)_.*$/(?1:$1)/ga}}")
38+
endsnippet
39+
740
snippet lib "Import a library"
841
library(${0:package})
942
endsnippet

0 commit comments

Comments
 (0)