From 6bbe8b5598c12bee7b49b0d45cb32feeba3b1ca4 Mon Sep 17 00:00:00 2001 From: Josh Bode Date: Fri, 10 Aug 2012 23:58:38 +1000 Subject: [PATCH 1/2] Added R snippets --- snippets/r.snippets | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 snippets/r.snippets diff --git a/snippets/r.snippets b/snippets/r.snippets new file mode 100644 index 0000000..44a2b9b --- /dev/null +++ b/snippets/r.snippets @@ -0,0 +1,32 @@ +snippet #! + #!/usr/bin/env Rscript + +# includes +snippet lib + library(${1:package}) +snippet req + require(${1:package}) +snippet source + source('${1:file}') + +# conditionals +snippet if + if (${1:condition}) { + ${2:code} + } +snippet else + else { + ${1:code} + } +snippet ei + else if (${1:condition}) { + ${2:code} + } + +# functions +snippet fun + ${1:name} = function (${2:variables}) { + ${3:code} + } +snippet ret + return(${1:code}) From b554adc78d95389b38a472232f40ec56ea1ec734 Mon Sep 17 00:00:00 2001 From: Josh Bode Date: Sat, 11 Aug 2012 00:44:45 +1000 Subject: [PATCH 2/2] Added *apply, **ply functions and array types. --- snippets/r.snippets | 65 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/snippets/r.snippets b/snippets/r.snippets index 44a2b9b..909e70d 100644 --- a/snippets/r.snippets +++ b/snippets/r.snippets @@ -14,7 +14,7 @@ snippet if if (${1:condition}) { ${2:code} } -snippet else +snippet el else { ${1:code} } @@ -30,3 +30,66 @@ snippet fun } snippet ret return(${1:code}) + +# dataframes, lists, etc +snippet df + ${1:name}[${2:rows}, ${3:cols}] +snippet c + c(${1:items}) +snippet li + list(${1:items}) +snippet mat + matrix(${1:data}, nrow=${2:rows}, ncol=${3:cols}) + +# apply functions +snippet apply + apply(${1:array}, ${2:margin}, ${3:function}) +snippet lapply + lapply(${1:list}, ${2:function}) +snippet sapply + lapply(${1:list}, ${2:function}) +snippet vapply + vapply(${1:list}, ${2:function}, ${3:type}) +snippet mapply + mapply(${1:function}, ${2:...}) +snippet tapply + tapply(${1:vector}, ${2:index}, ${3:function}) +snippet rapply + rapply(${1:list}, ${2:function}) + +# plyr functions +snippet dd + ddply(${1:frame}, ${2:variables}, ${3:function}) +snippet dl + dlply(${1:frame}, ${2:variables}, ${3:function}) +snippet da + daply(${1:frame}, ${2:variables}, ${3:function}) +snippet d_ + d_ply(${1:frame}, ${2:variables}, ${3:function}) + +snippet ad + adply(${1:array}, ${2:margin}, ${3:function}) +snippet al + alply(${1:array}, ${2:margin}, ${3:function}) +snippet aa + aaply(${1:array}, ${2:margin}, ${3:function}) +snippet a_ + a_ply(${1:array}, ${2:margin}, ${3:function}) + +snippet ld + ldply(${1:list}, ${2:function}) +snippet ll + llply(${1:list}, ${2:function}) +snippet la + laply(${1:list}, ${2:function}) +snippet l_ + l_ply(${1:list}, ${2:function}) + +snippet md + mdply(${1:matrix}, ${2:function}) +snippet ml + mlply(${1:matrix}, ${2:function}) +snippet ma + maply(${1:matrix}, ${2:function}) +snippet m_ + m_ply(${1:matrix}, ${2:function})