Skip to contents

[Deprecated] Chunks are being deprecated qenv objects should be used instead

Format

An R6Class generator object

Methods

new(expression = NULL)

Create the object by setting the expression field which needs to be of type call.

eval(envir = parent.frame()

Evaluation of this code chunk. The value of the evaluated chunk with substitution of the variables by the environment values.

get_eval_info()

Returns a list with 5 elements: code, evaluation information, messages information, warnings information and errors information.

get_rcode(envir = parent.frame()

For the code chunk with the string of the R-Code is returned.

is_ok()

Get the information if the execution went right.

info()

Derive all slots this class carries. Slots are private and can just be derived by the info function which will return a list.

info_msg()

Get a formatted string of the evaluated code and caught warnings and errors.

get_errors()

Get a string of errors caught during evaluation.

get_warnings()

Get a string of warnings caught during evaluation.

get_messages()

Get a string of messages caught during evaluation.

is_evaluated()

Return TRUE if chunk was evaluated, FALSE otherwise.

is_warnings()

Return TRUE if chunk was evaluated and output any messages, FALSE otherwise.

is_messages()

Return TRUE if chunk was evaluated and output any messages, FALSE otherwise.

Examples

y <- 0
x <- chunk$new(expression = quote(y <- 1))

x$get_rcode()
#> [1] "y <- 1"
x$is_ok()
#> [1] FALSE
x$info_msg()
#> [1] "Chunk not evaluated yet."
x$eval()
x$is_ok()
#> [1] TRUE
cat(x$info_msg())
#> Everything went well!
#> 
#> when evaluating the following code:
#> y <- 1
y == 1
#> [1] TRUE

# error handling
x <- chunk$new(expression = call("stop", "test"))
x$eval()
x$is_ok()
#> [1] FALSE
x$info_msg()
#> [1] "The following errors(s) occurred:\ntest\n\nwhen evaluating the following code:\nstop(\"test\")\n"
x$info()
#> $expression
#> stop("test")
#> 
#> $is_evaluated
#> [1] TRUE
#> 
#> $is_error
#> [1] TRUE
#> 
#> $is_warning
#> [1] FALSE
#> 
#> $is_message
#> [1] FALSE
#> 
#> $eval_msg
#> [1] "test"
#>