Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


realtest (version 0.2.3)

source2: Read and Evaluate Code from an R Script

Description

A simplified alternative to source, which additionally sets some environment variables whilst executing a series of expressions to ease debugging.

Usage

source2(file, local = FALSE)

Value

This function returns nothing.

Arguments

file

usually a file name, see parse

local

specifies the environment where expressions will be evaluated, see source

Details

The function sets/updates the following environment variables while evaluating consecutive expressions:

  • __FILE__ -- path to the current file,

  • __LINE__ -- line number where the currently executed expression begins,

  • __EXPR__ -- source code defining the expression.

See Also

The official online manual of realtest at https://realtest.gagolewski.com/

Examples

Run this code
# \donttest{
# example error handler - report source file and line number
old_option_error <- getOption("error")
options(error=function()
   cat(sprintf(
       "Error in %s:%s.\n", Sys.getenv("__FILE__"), Sys.getenv("__LINE__")
   ), file=stderr()))
# now call source2() to execute an R script that throws some errors...
options(error=old_option_error)  # cleanup
# }

Run the code above in your browser using DataLab