make_file: Make me a Makefile

Description Usage Arguments Details

Description

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

Usage

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

Arguments

path

Directory containing R scripts or a single file

script.all

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

read.fun

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

write.fun

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

read.arg

Name of argument specifying the file read

write.arg

Name of argument specifying the file written

script

A named list of shell commands for specific file types

dry

Should a Makefile be written (TRUE) or printed?

Details

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 read.fun 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/dataglue documentation built on May 18, 2019, 10:22 p.m.