-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathrmd.snippets
149 lines (127 loc) · 3.21 KB
/
rmd.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
#
# Snipmate Snippets for Pandoc Markdown
#
# Many snippets have starred versions, i.e., versions
# that end with an asterisk (`*`). These snippets use
# vim's `"*` register---i.e., the contents of the
# system clipboard---to insert text.
extends markdown
# Insert Title Block
snippet %%
% ${1:`Filename('', 'title')`}
% ${2:`g:snips_author`}
% ${3:`strftime("%d %B %Y")`}
${4}
snippet %%*
% ${1:`Filename('', @*)`}
% ${2:`g:snips_author`}
% ${3:`strftime("%d %b %Y")`}
${4}
# library()
snippet req
require(${1:}, quietly = TRUE)
# If Condition
snippet if
if ( $1 )
{
${2:}
}
snippet el
else
{
${1:}
}
# Function
snippet fun
${1:funname} <- # ${2:}
function
(
${3:}
)
{
${4:}
}
# repeat
snippet re
repeat{
${2:}
if($1) break
}
# matrix
snippet ma
matrix(NA, nrow = ${1:}, ncol = ${2:})
# data frame
snippet df
data.frame(${1:}, header = TRUE)
snippet cmdarg
args <- commandArgs(TRUE)
if (length(args) == 0)
stop("Please give ${1:}!")
if (!all(file.exists(args)))
stop("Couln't find input files!")
snippet getopt
require('getopt', quietly = TRUE)
opt_spec <- matrix(c(
'help', 'h', 0, "logical", "Getting help",
'file', 'f', 1, "character","File to process"
), ncol = 5, byrow = TRUE)
opt <- getopt(spec = opt_spec)
if ( !is.null(opt$help) || is.null(commandArgs()) ) {
cat(getopt(spec = opt_spec, usage = TRUE, command = "yourCmd"))
q(status=0)
}
# some inital value
if ( is.null(opt$???) ) { opt$??? <- ??? }
snippet optparse
require("optparse", quietly = TRUE)
option_list <-
list(make_option(c("-n", "--add_numbers"), action="store_true", default=FALSE,
help="Print line number at the beginning of each line [default]")
)
parser <- OptionParser(usage = "%prog [options] file", option_list=option_list)
arguments <- parse_args(parser, positional_arguments = TRUE)
opt <- arguments$options
if(length(arguments$args) != 1) {
cat("Incorrect number of required positional arguments\n\n")
print_help(parser)
stop()
} else {
file <- arguments$args
}
if( file.access(file) == -1) {
stop(sprintf("Specified file ( %s ) does not exist", file))
} else {
file_text <- readLines(file)
}
snippet #!
#!/usr/bin/env Rscript
snippet debug
# Development & Debugging, don't forget to uncomment afterwards!
#--------------------------------------------------------------------------------
#setwd("~/Projekte/${1:}")
#opt <- list(${2:}
# )
#--------------------------------------------------------------------------------
# Took from pandoc-plugin <<<<
# Underline with `=`s or `-`s
snippet #===
#`repeat('=', strlen(getline(line(".") - 1)))`
${1}
snippet #---
#`repeat('-', strlen(getline(line(".") - 1)))`
${1}
# >>>>
snippet r
\`\`\`{r ${1:chung_tag}, echo = FALSE ${2:options}}
${3:}
\`\`\`
snippet ri
\`{r ${1:}}\`
snippet copt
\`\`\` {r setup, echo = FALSE}
opts_chunk$set(fig.path='../figures/${1:}', cache.path='../cache/-'
, fig.align='center', fig.show='hold', par=TRUE)
#opts_knit$set(upload.fun = imgur_upload) # upload images
\`\`\`
# End of File ===================================================================
# vim: set noexpandtab: