-
Notifications
You must be signed in to change notification settings - Fork 0
/
r.snippets
159 lines (122 loc) · 2.7 KB
/
r.snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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) {
}
)
}
snippet hdsc
#!/usr/bin/env Rscript
library("optparse")
opt_parser = OptionParser(description = "
##_Script title_################################################################
Version = '0.0.1'
Date = '2024-01-15'
Author = 'Yoann PAGEAUD'
Maintainer = 'Yoann PAGEAUD ([email protected])'
Dependencies = c('R version 4.3.3 (2024-02-29)',
'RStudio 2023.09.1 Build 494 © 2009-2023','!!Add dependencies here!!')
Description = 'script description here'
################################################################################
");
if (is.null(parse_args(opt_parser)\$file) != TRUE){print_help(opt_parser);quit()}
snippet imp
##IMPORTS
setwd("")
Imports = c("pkgs")
invisible(lapply(Imports, library, character.only = T))
snippet para
##PARAMETERS
snippet ana
##ANALYSIS
snippet funtitle
##FUNCTIONS
snippet hdfn
#' Write function description here.
#'
#' @param param1 A \code{type} parameter description.
#' @return A \code{type} object returned description.
#' @author Yoann Pageaud.
#' @export
#' @examples
#' @references
#' @keywords internal