From b76fe5e8ef8dabf5a5eb3aae447b0bbb93169a5c Mon Sep 17 00:00:00 2001 From: emzap79 Date: Mon, 9 Jun 2014 10:31:58 +0200 Subject: [PATCH] add cleaned-up snippets for R --- UltiSnips/r.snippets | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/UltiSnips/r.snippets b/UltiSnips/r.snippets index 74ecc1d..10c818c 100644 --- a/UltiSnips/r.snippets +++ b/UltiSnips/r.snippets @@ -1,9 +1,42 @@ priority -50 +global !p +import os +from vimsnippets import complete + +FIELD_TYPES = [ +'character', +'data.frame', +'integer', +'list', +'logical', +'matrix', +'numeric', +'vector'] +endglobal + snippet #! "Hashbang for Rscript (#!)" b #!/usr/bin/env Rscript endsnippet +snippet setwd "Set workingdir" b +setwd("${1:`!p snip.rv = os.getcwd()`}") +endsnippet + +snippet as "Apply type on variable" w +as.$1`!p snip.rv = complete(t[1], FIELD_TYPES)`(${2}${VISUAL}) +endsnippet + +snippet is "Test type on variable" w +is.$1`!p snip.rv = complete(t[1], FIELD_TYPES)`(${2}${VISUAL}) +endsnippet + +snippet dl "Download and install a package" b +download.file("${1:${VISUAL:url to package}}", destfile = "${2:${1/.*\/(\S*)$/(?1:$1)/ga}}") +install.packages("$2", type = "source", repos = NULL) +library("${3:${2/^(\w+)_.*$/(?1:$1)/ga}}") +endsnippet + snippet lib "Import a library" library(${0:package}) endsnippet