Last active
October 21, 2023 01:55
-
-
Save RaymondBalise/3c3ca9abe840488c747056ef0eae16f2 to your computer and use it in GitHub Desktop.
Autocomplete Snippets for RStudio
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
# version 2022-08-23 | |
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}Server <- function(id) { | |
moduleServer( | |
id, | |
function(input, output, session) { | |
} | |
) | |
} | |
##### Ray was here ##### | |
snippet ggviolin | |
ggplot(aes(x = ${1:factor}, y = ${2:numeric})) + | |
geom_violin(draw_quantiles = c(.25, .5, .75)) + | |
stat_summary(fun = mean, geom = "point", shape = 4, size = 4, color = "red") + | |
labs( | |
title = "${3:title}", | |
y = "${4:label}" | |
) + | |
theme_few() + | |
theme(axis.title.x = element_blank()) | |
# mutate case when | |
snippet mcw | |
mutate(${1:variable} = | |
case_when( | |
${2:condition} ~ ${3:value}, | |
${4:condition} ~ ${5:value}, | |
TRUE ~ ${6:otherwise} | |
) | |
) | |
# mutate if else | |
snippet mie | |
mutate(${1:variable} = | |
if_else( | |
${2:condition}, ${5:if_value}, ${6:else_value} | |
) | |
) | |
# shiny multi-row layout | |
snippet shinymr | |
library(shiny) | |
ui <- | |
fluidPage( | |
fluidRow( | |
column(4, | |
${1:content} | |
), | |
column(8, | |
) | |
), | |
fluidRow( | |
column(6, | |
), | |
column(6, | |
) | |
) | |
) | |
server <- function(input, output, session) { | |
} | |
shinyApp(ui, server) | |
# shiny sidebar layout | |
snippet shinysb | |
library(shiny) | |
ui <- fluidPage( | |
titlePanel( | |
"${1:title}" | |
), | |
sidebarLayout( | |
sidebarPanel( | |
${2:inputs} | |
), | |
mainPanel( | |
) | |
) | |
) | |
server <- function(input, output, session) { | |
} | |
shinyApp(ui, server) | |
# quarto hash pipe | |
snippet hp | |
#| ${1:option} | |
# quarto hash pipe | |
snippet hpl | |
#| label: ${1:label} | |
# quarto hash pipe for figure | |
snippet hpf | |
#| label: fig-${1:label} | |
#| fig-cap: ${2:caption} | |
#| echo: false | |
# quarto hash pipe for table | |
snippet hpt | |
#| label: tbl-${1:label} | |
#| tbl-cap: ${2:caption} | |
#| echo: false |
Version 2022-05-24
- add shiny multi-row layout
Version 2022-05-26
- Fixed missing shinyApp() in shinymr
Version 2022-08-23
- Add Quarto hash pipes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version 2022-05-17