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.

Log attributes

The following attributes are recorded in the log:

  • metadata: The logrx package information
  • user and file information: The user that generates the log, file name and path of the R script
  • session_info: The R session information
  • packages: List all available packages in the environment
  • external_software" Lists all external software
  • masked_functions: The functions masked by packages
  • start_time, end_time, and run_time: The start, end, and run times
  • used_packages_functions: Any packages and functions used in the R script
  • unapproved_packages_functions: Any packages and functions used in the R script that are not part of that approved packages and functions list
  • errors: The errors generated when running the R script
  • warnings: The warnings generated when running the R script
  • messages: The messages generated when running the R script
  • result: The result generated when running the R script
  • output: The output generated when running the R script
  • log_name, log_path: The name and path of the log

Generating a log

The log can be generated according in two ways:

  • Using the axecute() function

  • Using the log_*() functions


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).


log_*() functions

Use 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


Scripting with 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().

r_script_list <- list.files(path = ".", pattern = "\\.R$")
lapply(r_script_list, axecute)