Title: | Run R Scripts if Needed |
---|---|
Description: | Automation tool to run R scripts if needed, based on last modified time. Implemented in base R with no additional software requirements, organizational overhead, or structural requirements. In short: run an R script if underlying files have changed, otherwise do nothing. |
Authors: | Arni Magnusson [aut, cre] |
Maintainer: | Arni Magnusson <[email protected]> |
License: | GPL-3 |
Version: | 1.0.1 |
Built: | 2024-10-31 21:08:39 UTC |
Source: | https://github.com/arni-magnusson/makeit |
Run an R script if underlying files have changed, otherwise do nothing.
make(recipe, prereq, target, include = TRUE, details = FALSE, force = FALSE, recon = FALSE, quiet = FALSE, ...)
make(recipe, prereq, target, include = TRUE, details = FALSE, force = FALSE, recon = FALSE, quiet = FALSE, ...)
recipe |
script filename. |
prereq |
one or more files required by the script. For example, data
files, scripts, or |
target |
one or more output files produced by the script. Directory names can also be used. |
include |
whether to automatically include the script itself as a prerequisite file. This means that if the script file has been modified, it should be run. |
details |
whether to show a diagnostic table of files and time last modified. |
force |
whether to run the R script unconditionally. |
recon |
whether to return |
quiet |
whether to suppress messages. |
... |
passed to |
TRUE
or FALSE
, indicating whether the script was run.
This function provides functionality similar to makefile rules, to determine whether a script should be (re)run or not.
If any target
is either missing or is older than any prereq
,
then the script is run.
Stallman, R. M. et al. An introduction to makefiles. Chapter 2 in the GNU Make manual.
See vignette("makeit")
for annotated examples and discussion.
file.exists
and file.mtime
are the underlying
functions used to check if files are missing or have changed.
source
is the underlying function to run a script.
# Copy examples 'analysis' and 'sequential' to temporary directory exdir <- tempdir() file.copy(system.file("examples/analysis", package="makeit"), exdir, recursive=TRUE) file.copy(system.file("examples/sequential", package="makeit"), exdir, recursive=TRUE) owd <- getwd() # This analysis uses input.dat to produce output.dat setwd(file.path(exdir, "analysis")) dir() make("analysis.R", "input.dat", "output.dat") # Running analysis.R dir() make("analysis.R", "input.dat", "output.dat") # Nothing to be done # Suppress message, show last modified make("analysis.R", "input.dat", "output.dat", quiet=TRUE) make("analysis.R", "input.dat", "output.dat", details=TRUE) # Sequential scripts setwd(file.path(exdir, "sequential")) print.simple.list(dir(recursive=TRUE)) make("01_model.R", "data.dat", "results.dat") make("02_plots.R", "results.dat", c("plots/A.png", "plots/B.png")) make("03_tables.R", "results.dat", c("tables/A.csv", "tables/B.csv")) print.simple.list(dir(recursive=TRUE)) # Clean up unlink(file.path(exdir, c("analysis", "sequential")), recursive=TRUE) setwd(owd) # See vignette("makeit") for more examples and discussion
# Copy examples 'analysis' and 'sequential' to temporary directory exdir <- tempdir() file.copy(system.file("examples/analysis", package="makeit"), exdir, recursive=TRUE) file.copy(system.file("examples/sequential", package="makeit"), exdir, recursive=TRUE) owd <- getwd() # This analysis uses input.dat to produce output.dat setwd(file.path(exdir, "analysis")) dir() make("analysis.R", "input.dat", "output.dat") # Running analysis.R dir() make("analysis.R", "input.dat", "output.dat") # Nothing to be done # Suppress message, show last modified make("analysis.R", "input.dat", "output.dat", quiet=TRUE) make("analysis.R", "input.dat", "output.dat", details=TRUE) # Sequential scripts setwd(file.path(exdir, "sequential")) print.simple.list(dir(recursive=TRUE)) make("01_model.R", "data.dat", "results.dat") make("02_plots.R", "results.dat", c("plots/A.png", "plots/B.png")) make("03_tables.R", "results.dat", c("tables/A.csv", "tables/B.csv")) print.simple.list(dir(recursive=TRUE)) # Clean up unlink(file.path(exdir, c("analysis", "sequential")), recursive=TRUE) setwd(owd) # See vignette("makeit") for more examples and discussion