library(logrx)
The purpose of the logrx
package is to generate a log
upon execution of an R script which enables traceability and
reproducibility of the executed code.
The following attributes are recorded in the log:
metadata
: The logrx package
informationuser and file information
: The user that generates the
log, file name and path of the R scriptsession_info
: The R session informationpackages
: List all available packages in the
environmentexternal_software
” Lists all external softwaremasked_functions
: The functions masked by packagesstart_time
, end_time
, and
run_time
: The start, end, and run timesused_packages_functions
: Any packages and functions
used in the R scriptunapproved_packages_functions
: Any packages and
functions used in the R script that are not part of that approved
packages and functions listerrors
: The errors generated when running the R
scriptwarnings
: The warnings generated when running the R
scriptmessages
: The messages generated when running the R
scriptresult
: The result generated when running the R
scriptoutput
: The output generated when running the R
scriptlog_name
, log_path
: The name and path of
the logThe log can be generated according in two ways:
Using the axecute()
function
Using the log_*()
functions
axecute()
axecute()
enables the command line submission of a
program. A log is set-up around the program, and its code is run safely
and loudly (using safely()
from the purrr
package).
axecute("my_script.R")
log_*()
functionsUse the log_*()
functions:
log_init()
to create the environment log.rx
log_config()
to add the core elements of the log to
the environment, and basic elements that are available at the time of
configuration
run_safely_loudly()
to execute the program code, and
capture errors, warnings, messages, output, and result
log_write()
to generate and format the log
log_config("my_script.R")
run_safely_loudly("my_script.R")
log_write()
logrx
While logrx
is built around creating a log for a program
it can just as easily be used when running an entire set of programs.
The axecute()
function has been built with both single file
execution and scripted file execution in mind. With the use of simple
functions such as lapply()
scripting is easy. Below is some
sample code of how lapply()
can be used with
axecute()
.
lapply(c("file.R", "otherfile.R"), axecute)
If your scripting needs to work on the contents of a directory
instead of a pre-defined list, functions such as list.files
can be used to obtain a list of files to use. Below is an example of how
this can be applied in practice by getting all files ending in ‘.R’ in
the current working directory using a regular expression, and then using
lapply()
to run the files using axecute()
.
<- list.files(path = ".", pattern = "\\.R$")
r_script_list lapply(r_script_list, axecute)