[更新一个工作示例是Sconstruct
文件:
import os
environment = Environment(ENV=os.environ)
# define a `knitr` builder
builder = Builder(action = '/usr/local/bin/knit $SOURCE -o $TARGET',
src_suffix='Rmd')
# add builders as "Knit", "RMD"
environment.Append(BUILDERS = {'Knit' : builder})
# define an `rmarkdown::render()` builder
builder = Builder(action = '/usr/bin/Rscript -e "rmarkdown::render(input=\'$SOURCE\', output_file=\'$TARGET\')"',
src_suffix='Rmd')
environment.Append(BUILDERS = {'RMD' : builder})
# define source (and target files -- currently useless, since not defined above!)
# main cleaning session code
environment.RMD(source='cleaning_session.Rmd', target='cleaning_session.html')
# documentation of the Cleaning Process
environment.Knit(source='Cleaning_Process.Rmd', target='Cleaning_Process.html')
# documentation of data
environment.Knit(source='Code_Book.Rmd', target='Code_Book.html')
第一建设者调用名为knit
自定义脚本。其中,反过来,照顾目标文件/扩展名,这里是cleaning_session.html
。在这个例子中,可能完全不需要suffix
参数。
第二个建造者加入的是Rscript -e "rmarkdown::render(\'$SOURCE\')"'
。
$TARGET
s的存在(如在Command wrapper的示例中)确保SCons
在目标文件已存在的情况下不会重复工作。
自定义脚本(其源我目前不能检索)是:
#!/usr/bin/env Rscript
local({
p = commandArgs(TRUE)
if (length(p) == 0L || any(c('-h', '--help') %in% p)) {
message('usage: knit input [input2 input3] [-n] [-o output output2 output3]
-h, --help to print help messages
-n, --no-convert do not convert tex to pdf, markdown to html, etc
-o output filename(s) for knit()')
q('no')
}
library(knitr)
o = match('-o', p)
if (is.na(o)) output = NA else {
output = tail(p, length(p) - o)
p = head(p, o - 1L)
}
nc = c('-n', '--no-convert')
knit_fun = if (any(nc %in% p)) {
p = setdiff(p, nc)
knit
} else {
if (length(p) == 0L) stop('no input file provided')
if (grepl('\\.(R|S)(nw|tex)$', p[1])) {
function(x, ...) knit2pdf(x, ..., clean = TRUE)
} else {
if (grepl('\\.R(md|markdown)$', p[1])) knit2html else knit
}
}
mapply(knit_fun, p, output = output, MoreArgs = list(envir = globalenv()))
})
唯一的事情,现在,必要的是运行scons
。
您能否给我们一个提示,如何将'.Rmd'文件转换为TeX/LaTeX的命令看起来像?然后,您只需按照https://bitbucket.org/scons/scons/wiki/ToolsForFools的建议将此命令转换为“Command”或适当的Builder,然后将创建的TeX文件称为来源到PDF生成器。然后SCONS应该照顾其余的...... – dirkbaechle
@dirkbaechle感谢您指出正确的文档。最后,我会尝试构建更详尽的内容。 –