Rmarkdown
Rmd to R scripts
Rmd 文件转化为 R 脚本,不运行 R 代码。
knitr::purl("test.Rmd","test.R", documentation = 2)
# doucumenation:0、不输出注释
# 1、输出函数外注释
# 2、输出所有注释
运行 R 代码并输出 html 等等
rmarkdown::render(input="path_to_your_file.rmd",
quiet = TRUE, # 不输出编译的过程
output_format = “html_document” #“pdf_document” “word_document”
output_file='output.html' # 默认输出 html
output_dir = './path/to/')
通过 bash 运行 Rmd
Rscript -e "rmarkdown::render('report.Rmd', output_dir='path/to/output_directory')"
# 会生成 report.html 文件
Jupyter Notebook
ipynb to scripts
提取 ipynb 中的代码为脚本
jupyter nbconvert --to script your_notebook.ipynb
运行脚本并输出 html
jupyter nbconvert --execute --to html your_notebook.ipynb
jupyter nbconvert --to notebook --execute your_notebook.ipynb --output executed_notebook.ipynb