Run a user-supplied script with arguments
run_script_with_args.Rd
This function sources and executes an R script from a specified file path in a new environment, optionally passing objects to that environment.
Examples
# Create a sample data frame
my_data <- data.frame(a = 1:5, b = letters[1:5])
# Create a temporary script for demonstration
temp_script <- tempfile(fileext = ".R")
writeLines(
"print('Executing script with data...')\nprint(head(data))",
temp_script
)
# Run the script, passing the data frame
run_script_with_args(temp_script, data = my_data)
#> Running script: /tmp/Rtmp6vMk6o/file6df27a8ae444.R
#> [1] "Executing script with data..."
#> a b
#> 1 1 a
#> 2 2 b
#> 3 3 c
#> 4 4 d
#> 5 5 e
# Clean up
unlink(temp_script)