A simplified alternative to source
, which additionally sets some environment variables whilst executing a series of expressions to ease debugging.
source2(file, local = FALSE)
| | |
|----|----|
| file
| usually a file name, see parse
|
| local
| specifies the environment where expressions will be evaluated, see source
|
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.
This function returns nothing.
The official online manual of realtest at https://realtest.gagolewski.com/
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.