Skip to content

Instantly share code, notes, and snippets.

@jimjam-slam
Created February 22, 2018 23:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimjam-slam/cf503f25834a9b79b70d6c078a2b698c to your computer and use it in GitHub Desktop.
Save jimjam-slam/cf503f25834a9b79b70d6c078a2b698c to your computer and use it in GitHub Desktop.
Visual Studio Code snippets for working with RMarkdown files. Go to Configure User Snippets and drop it in.
{
// Snippets for talking to yourself
"TK (citation needed)": {
"prefix": "tkcite",
"body": "_(**TKTK** - citation needed)_",
"description": "Add a note to yourself to cite this later."
},
"TK": {
"prefix": "tktk",
"body": "_(**TKTK** - blah blah blah)_",
"description": "Add a note to yourself."
},
// Snippets for inserting figures and tables
"Figure": {
"prefix": "addfig",
"body": [
"```{r ${1:chunkref}, fig.cap = \"${3:caption}\"}",
"knitr::include_graphics('figure/${2:file}')",
"```"
],
"description": "Add a figure"
},
"Figure with external caption": {
"prefix": "addfig_extcap",
"body": [
"(ref:${1:chunkref}-cap) {3:caption}",
"",
"```{r ${1:chunkref}, fig.cap = (ref:${1:chunkref}-cap)}",
"knitr::include_graphics('figure/${2:file}')",
"```"
],
"description": "Add a figure with an external caption (for things like Markdown or citations in captions)."
},
"Table from CSV": {
"prefix": "addtab_csv",
"body": [
"```{r ${1:chunkref}, eval = TRUE, echo = FALSE, message = FALSE, results = 'asis'}",
"knitr::kable(",
"\tread_csv('data/${2:file}'),",
"\tbooktabs = TRUE,",
"\tcaption = \"${3:caption}\")",
"```"
],
"description": "Add a table from a CSV file using Kable."
},
// Snippets for cross-referncing
"Cross-reference figure": {
"prefix": "crossref_fig",
"body": "\\@ref(fig:${1:chunkref})",
"description": "Cross reference a figure, like (Figure X)."
},
"Cross-reference table": {
"prefix": "crossref_tab",
"body": "\\@ref(tab:${1:chunkref})",
"description": "Cross reference a table, like (Table X)."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment