[更新一個工作示例是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感謝您指出正確的文檔。最後,我會嘗試構建更詳盡的內容。 –