To compile Rmd files to PDF with a Makefile

This commit is contained in:
Pierre-Edouard Portier 2022-02-19 19:04:58 +01:00
parent c31e8b9ef3
commit d1e4ac7a26
2 changed files with 27 additions and 0 deletions

4
Makefile Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env make
%.pdf: %.Rmd
@R --quiet --file=make.R --args $<

23
make.R Normal file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env R
# Render R markdown to PDF.
# Invoke with:
# > R -q -f make.R --args my_report.Rmd
# load packages
require(rmarkdown)
# require a parameter naming file to render
if (length(args) == 0) {
stop("Error: missing file operand", call. = TRUE)
} else {
# read report to render from command line
for (rmd in commandArgs(trailingOnly = TRUE)) {
# render Rmd to PDF
if ( grepl("\\.Rmd$", rmd) && file.exists(rmd)) {
render(rmd, pdf_document())
} else {
print(paste("Ignoring: ", rmd))
}
}
}