run_file: Run a file while tracking changes in data

View source: R/run.R

run_fileR Documentation

Run a file while tracking changes in data

Description

Run all code in a file. Changes in data that are tracked, (e.g. with start_log(data)) will be followed by the assigned loggers.

Usage

run_file(file, auto_dump = TRUE, envir = NULL)

source_file(file, auto_dump = TRUE)

Arguments

file

[character] file to run.

auto_dump

[logical] Toggle automatically dump all remaining logs after executing file.

envir

[environment] to run the code in. By default a new environment will be created with .GlobalEnv as parent.

Value

The environment where the code was executed, invisibly.

Details

run\_file runs code in a separate environment, and returns the environment with all the variables created by the code. source\_file acts like source and runs all the code in the current global workspace (.GlobalEnv).

See Also

Other control: %>>%(), dump_log(), get_log(), start_log(), stop_log()

Examples

# using 'dontrun'
## Not run: 
# create an R file, with logging.
script <- "
library(lumberjack)
data(women)
start_log(women, logger=simple$new())
women$height <- women$height*2.54
women$weight <- women$weight*0.453592
dump_log()
"
write(script, file="myscript.R")
# run the script
lumberjack::run_file("myscript.R")
# read the logfile
read.csv("women_simple.csv")

## End(Not run)


lumberjack documentation built on March 31, 2023, 7:56 p.m.