make_file: Make me a Makefile

Description Usage Arguments Details

View source: R/make_file.R


Determine targets and prerequisites based on data files that are read/written in your working directory. Make targets by running scripts.


make_file(path = ".", script.all = NULL, = c("read", "load"), = c("write", "save"), read.arg = "[Ff]ile",
  write.arg = read.arg, script = list(R = "Rscript \"$(<)\"", Rmd =
  "Rscript -e \"rmarkdown::render('$(<)')\""), dry = FALSE)



Directory containing R scripts or a single file


Which script produces the ultimate target? By default a script that creates targets on which nothing else depends

Vector of (partial) function names; e.g. "read" matches both read.csv and readRds.

Vector of (partial) function names; e.g. "save" matches both save and saveRDS.


Name of argument specifying the file read


Name of argument specifying the file written


A named list of shell commands for specific file types


Should a Makefile be written (TRUE) or printed?


make_file() will parse the R code in 'path' and search for function calls that read/write data files. It uses partial matching, so if is set to "read", it will match read.delim, read.table, readRds etc.

The purpose of this is to extract the values of the file argument from these calls and create a list of files that are being read/written. (You can actually choose different argument but file seems like the most sensible default. Partial matching applies here as well so file and xlsxFile are both matched by "file".)

In order for this to work, use named file argument in your function calls, e.g. load(file = "myfile.RData") and not load("myfile.RData"), otherwise the parser will ignore it.

Once the list of data files is obtained, a Makefile is created, using files that were written as targets and files that were read as prerequisites. The scripts that do the reading/writing become commands. By default, the shell command for R files is "Rscript \"myfile.R\"" and for Rmd files "Rscript -e \"rmarkdown::render('myfile.Rmd')\"".

If DRY is TRUE, the Makefile is just printed on the console.

jchrom/datamake documentation built on May 17, 2017, 1:58 p.m.