Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions UltiSnips/r.snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
snippet #! "Hashbang for Rscript"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add snippet options where appropriate. For example this here should only expand at the beginning of the line, so add "b" at the end.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing priority line: priority -50

Otherwise users will have a hard time overriding any of these snippets.

#!/usr/bin/env Rscript
endsnippet

# includes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment seems useless?

snippet lib "Import a library"
library(${0:package})
endsnippet

snippet req "Require a file"
require(${0:package})
endsnippet

snippet source "Source a file"
source('${0:file}')
endsnippet

# conditionals
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, I think the comments are not adding value, but will probably go out of sync as soon as somebody adds new snippets.

snippet if "If statement"
if (${1:condition}) {
${0}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github does not show, but are you indenting with tabs? Please make sure you use tabs everywhere.

}
endsnippet

snippet el "Else statement"
else {
${0}
}
endsnippet

snippet ei "Else-If statement"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if (${1:condition}) {
${0}
}
endsnippet

# functions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment?

snippet fun "Function definition"
${1:name} <- function (${2:variables}) {
${0}
}
endsnippet

snippet ret "Return call"
return(${0})
endsnippet

# dataframes, lists, etc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this for sure.

snippet df "Data frame"
${1:name}[${2:rows}, ${0:cols}]
endsnippet

snippet c "C function"
c(${0:items})
endsnippet

snippet li "List function"
list(${0:items})
endsnippet

snippet mat "Matrix function"
matrix(${1:data}, nrow = ${2:rows}, ncol = ${0:cols})
endsnippet

# apply functions
snippet apply "Apply function"
apply(${1:array}, ${2:margin}, ${0:function})
endsnippet

snippet lapply "lapply function"
lapply(${1:list}, ${0:function})
endsnippet

snippet sapply "sapply function"
lapply(${1:list}, ${0:function})
endsnippet

snippet vapply "vapply function"
vapply(${1:list}, ${2:function}, ${0:type})
endsnippet

snippet mapply "mapply function"
mapply(${1:function}, ${0:...})
endsnippet

snippet tapply "tapply function"
tapply(${1:vector}, ${2:index}, ${0:function})
endsnippet

snippet rapply "rapply function"
endsnippet
rapply(${1:list}, ${0:function})

# plot functions
snippet pl "Plot function"
plot(${1:x}, ${0:y})
endsnippet

snippet ggp "ggplot2 plot"
ggplot(${1:data}, aes(${0:aesthetics}))
endsnippet

snippet img "Output an image"
${1:(jpeg,bmp,png,tiff)}(filename = "${2:filename}", width = ${3}, height = ${4}, unit = "${5}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a complete function for the TS 1? https://github.com/honza/vim-snippets/blob/master/UltiSnips/rst.snippets#L135

Feel free to copy and paste for now. I think we will have a python module of helper functions in the future.

${0:plot}
dev.off()
endsnippet

# statistical test functions
snippet fis "Fisher test"
fisher.test(${1:x}, ${0:y})
endsnippet

snippet chi "Chi Squared test"
chisq.test(${1:x}, ${0:y})
endsnippet

snippet tt "t-test"
t.test(${1:x}, ${0:y})
endsnippet

snippet wil "Wilcox test"
wilcox.test(${1:x}, ${0:y})
endsnippet

snippet cor "Correlation test"
cor.test(${1:x}, ${0:y})
endsnippet

snippet fte "FTE test"
var.test(${1:x}, ${0:y})
endsnippet

snippet kvt "KV test"
kv.test(${1:x}, ${0:y})
endsnippet
3 changes: 3 additions & 0 deletions UltiSnips/rnoweb.snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
priority -50

extends tex, r