-
Notifications
You must be signed in to change notification settings - Fork 2k
Add R snippets for UltiSnips #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
77bc9bd
53f8dd5
55887f0
bd8ef3d
d1f2316
6b5d7d3
8c7bb5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| snippet #! "Hashbang for Rscript" | ||
| #!/usr/bin/env Rscript | ||
| endsnippet | ||
|
|
||
| # includes | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trigger should be eif: https://github.com/honza/vim-snippets#policies--for-contributors |
||
| else if (${1:condition}) { | ||
| ${0} | ||
| } | ||
| endsnippet | ||
|
|
||
| # functions | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| priority -50 | ||
|
|
||
| extends tex, r |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.