@@ -53,48 +53,44 @@ setMethod("eval_code", signature = c(object = "qenv.error"), function(object, co
5353 return (object )
5454 }
5555 code_split <- split_code(paste(code , collapse = " \n " ))
56+
5657 for (i in seq_along(code_split )) {
5758 current_code <- code_split [[i ]]
5859 current_call <- parse(text = current_code , keep.source = TRUE )
59- # Using withCallingHandlers to capture warnings and messages.
60- # Using tryCatch to capture the error and abort further evaluation.
61- x <- withCallingHandlers(
62- tryCatch(
63- {
64- eval(current_call , envir = object @ .xData )
65- if (! identical(parent.env(object @ .xData ), parent.env(.GlobalEnv ))) {
66- # needed to make sure that @.xData is always a sibling of .GlobalEnv
67- # could be changed when any new package is added to search path (through library or require call)
68- parent.env(object @ .xData ) <- parent.env(.GlobalEnv )
69- }
70- NULL
71- },
72- error = function (e ) {
73- errorCondition(
74- message = sprintf(
75- " %s \n when evaluating qenv code:\n %s" ,
76- cli :: ansi_strip(conditionMessage(e )),
77- current_code
78- ),
79- class = c(" qenv.error" , " try-error" , " simpleError" ),
80- trace = unlist(c(object @ code , list (current_code )))
81- )
82- }
83- ),
84- warning = function (w ) {
85- attr(current_code , " warning" ) <<- cli :: ansi_strip(sprintf(" > %s\n " , conditionMessage(w )))
86- invokeRestart(" muffleWarning" )
87- },
88- message = function (m ) {
89- attr(current_code , " message" ) <<- cli :: ansi_strip(sprintf(" > %s" , conditionMessage(m )))
90- invokeRestart(" muffleMessage" )
91- }
60+ x <- evaluate :: evaluate(
61+ current_code ,
62+ envir = object @ .xData ,
63+ stop_on_error = 1 ,
64+ output_handler = evaluate :: new_output_handler(value = identity )
9265 )
9366
94- if (! is.null(x )) {
95- return (x )
67+ e <- Filter(function (e ) inherits(e , " error" ), x )
68+ if (length(e )) {
69+ return (
70+ errorCondition(
71+ message = sprintf(
72+ " %s \n when evaluating qenv code:\n %s" ,
73+ cli :: ansi_strip(conditionMessage(e [[1 ]])),
74+ current_code
75+ ),
76+ class = c(" qenv.error" , " try-error" , " simpleError" ),
77+ trace = unlist(c(object @ code , list (current_code )))
78+ )
79+ )
80+ }
81+ if (! identical(parent.env(object @ .xData ), parent.env(.GlobalEnv ))) {
82+ # needed to make sure that @.xData is always a sibling of .GlobalEnv
83+ # could be changed when any new package is added to search path (through library or require call)
84+ parent.env(object @ .xData ) <- parent.env(.GlobalEnv )
9685 }
97- attr(current_code , " dependency" ) <- extract_dependency(current_call )
86+
87+ attributes(current_code ) <- Filter(
88+ length ,
89+ list (
90+ dependency = extract_dependency(current_call ),
91+ outputs = x [- 1 ]
92+ )
93+ )
9894 object @ code <- c(object @ code , stats :: setNames(list (current_code ), sample.int(.Machine $ integer.max , size = 1 )))
9995 }
10096
0 commit comments