-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwin_bash.R
29 lines (27 loc) · 975 Bytes
/
win_bash.R
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
# Based on knitr::knit_engines$get('bash')
win_bash <- function (options)
{
cmd = 'C:/Users/Derek Slone-Zhen/.babun/cygwin/bin/bash.exe'
out = if (options$eval) {
message("running: ", cmd, " ", options$code)
code <- gsub("\r", "", options$code, fixed = TRUE)
tmp_file <- tempfile()
writeChar(code, tmp_file)
tryCatch(system2(cmd, options$engine.opts, stdout = TRUE, stderr = TRUE,
stdin = tmp_file,
env = options$engine.env),
error = function(e) {
if (!options$error)
stop(e)
paste("Error in running command", cmd, code)
},
finally = {
file.remove(tmp_file)
})
}
else ""
if (!options$error && !is.null(attr(out, "status")))
stop(paste(out, collapse = "\n"))
knitr::engine_output(options, options$code, out)
}
knitr::knit_engines$set(bash=win_bash)