Last active
September 26, 2023 15:09
-
-
Save remlapmot/caa52709e93a01863390972f0eb88776 to your computer and use it in GitHub Desktop.
R code snippets file for RStudio; file location on Windows: %appdata%\RStudio\snippets ; on Mac/Linux: ~/.config/rstudio/snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
snippet lib | |
library(${1:package}) | |
snippet req | |
require(${1:package}) | |
snippet src | |
source("${1:file.R}") | |
snippet ret | |
return(${1:code}) | |
snippet mat | |
matrix(${1:data}, nrow = ${2:rows}, ncol = ${3:cols}) | |
snippet sg | |
setGeneric("${1:generic}", function(${2:x, ...}) { | |
standardGeneric("${1:generic}") | |
}) | |
snippet sm | |
setMethod("${1:generic}", ${2:class}, function(${2:x, ...}) { | |
${0} | |
}) | |
snippet sc | |
setClass("${1:Class}", slots = c(${2:name = "type"})) | |
snippet if | |
if (${1:condition}) { | |
${0} | |
} | |
snippet el | |
else { | |
${0} | |
} | |
snippet ei | |
else if (${1:condition}) { | |
${0} | |
} | |
snippet fun | |
${1:name} <- function(${2:variables}) { | |
${0} | |
} | |
snippet for | |
for (${1:variable} in ${2:vector}) { | |
${0} | |
} | |
snippet while | |
while (${1:condition}) { | |
${0} | |
} | |
snippet switch | |
switch (${1:object}, | |
${2:case} = ${3:action} | |
) | |
snippet apply | |
apply(${1:array}, ${2:margin}, ${3:...}) | |
snippet lapply | |
lapply(${1:list}, ${2:function}) | |
snippet sapply | |
sapply(${1:list}, ${2:function}) | |
snippet mapply | |
mapply(${1:function}, ${2:...}) | |
snippet tapply | |
tapply(${1:vector}, ${2:index}, ${3:function}) | |
snippet vapply | |
vapply(${1:list}, ${2:function}, FUN.VALUE = ${3:type}, ${4:...}) | |
snippet rapply | |
rapply(${1:list}, ${2:function}) | |
snippet ts | |
`r paste("#", date(), "------------------------------\n")` | |
snippet shinyapp | |
library(shiny) | |
ui <- fluidPage( | |
${0} | |
) | |
server <- function(input, output, session) { | |
} | |
shinyApp(ui, server) | |
snippet shinymod | |
${1:name}_UI <- function(id) { | |
ns <- NS(id) | |
tagList( | |
${0} | |
) | |
} | |
${1:name} <- function(input, output, session) { | |
} | |
snippet hp | |
help(package = "${1:package-name}") | |
snippet bv | |
browseVignettes(package = "${1:package-name}") | |
snippet dv | |
devtools::install(build_vignettes = TRUE) | |
snippet up | |
update.packages(ask = FALSE) | |
snippet rup | |
remotes::update_packages() | |
snippet ig | |
remotes::install_github("${1:username}/${2:repo}") | |
snippet pp | |
"`r gsub('"', "", gsub("\\\\", "/", readClipboard()))`" | |
snippet ips | |
install.packages("${1:pkg-name}") | |
snippet sw | |
setwd("`r gsub('"', "", gsub("\\\\", "/", readClipboard()))`") | |
snippet p | |
%>% | |
snippet bc | |
BiocManager::install() | |
snippet ki | |
knitr::include_graphics("${1:filename}") | |
snippet ch | |
devtools::check(vignettes = FALSE) | |
snippet bch | |
BiocCheck::BiocCheck(, `no-check-vignettes`=TRUE) | |
snippet crn | |
devtools::check(env_vars = c(NOT_CRAN = "false")) | |
snippet op | |
rstudioapi::openProject(path = '.') | |
snippet cp | |
rstudioapi::executeCommand('closeProject') | |
snippet ip | |
rstudioapi::initializeProject() | |
snippet bih | |
blogdown::install_hugo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The additions to the default RStudio
r.snippets
file are after theshinymod
snippet.