@@ -33,25 +33,20 @@ setMethod("eval_code", signature = c("qenv", "character"), function(object, code
3333 return (object )
3434 }
3535
36- id <- sample.int(.Machine $ integer.max , size = length(parsed_code ))
37-
38- object @ id <- c(object @ id , id )
3936 object @ env <- rlang :: env_clone(object @ env , parent = parent.env(.GlobalEnv ))
40-
4137 code_split <- split_code(paste(code , collapse = " \n " ))
42- object @ code <- c(object @ code , unlist(code_split ))
43-
44- current_warnings <- rep(" " , length(parsed_code ))
45- current_messages <- rep(" " , length(parsed_code ))
4638
4739 for (i in seq_along(code_split )) {
48- single_call <- parse(text = code_split [[i ]], keep.source = FALSE )
40+ current_code <- code_split [[i ]]
41+ current_call <- parse(text = current_code , keep.source = FALSE )
42+ new_object_code <- c(object @ code , list (current_code ))
43+
4944 # Using withCallingHandlers to capture warnings and messages.
5045 # Using tryCatch to capture the error and abort further evaluation.
5146 x <- withCallingHandlers(
5247 tryCatch(
5348 {
54- eval(single_call , envir = object @ env )
49+ eval(current_call , envir = object @ env )
5550 if (! identical(parent.env(object @ env ), parent.env(.GlobalEnv ))) {
5651 # needed to make sure that @env is always a sibling of .GlobalEnv
5752 # could be changed when any new package is added to search path (through library or require call)
@@ -64,31 +59,30 @@ setMethod("eval_code", signature = c("qenv", "character"), function(object, code
6459 message = sprintf(
6560 " %s \n when evaluating qenv code:\n %s" ,
6661 .ansi_strip(conditionMessage(e )),
67- deparse1(single_call )
62+ deparse1(current_call )
6863 ),
6964 class = c(" qenv.error" , " try-error" , " simpleError" ),
70- trace = object @ code
65+ trace = unlist( new_object_code )
7166 )
7267 }
7368 ),
7469 warning = function (w ) {
75- current_warnings [ i ] <<- .ansi_strip(sprintf(" > %s\n " , conditionMessage(w )))
70+ attr( current_code , " warning " ) <<- .ansi_strip(sprintf(" > %s\n " , conditionMessage(w )))
7671 invokeRestart(" muffleWarning" )
7772 },
7873 message = function (m ) {
79- current_messages [ i ] <<- .ansi_strip(sprintf(" > %s" , conditionMessage(m )))
74+ attr( current_code , " message " ) <<- .ansi_strip(sprintf(" > %s" , conditionMessage(m )))
8075 invokeRestart(" muffleMessage" )
8176 }
8277 )
8378
8479 if (! is.null(x )) {
8580 return (x )
8681 }
87- }
88-
8982
90- object @ warnings <- c(object @ warnings , current_warnings )
91- object @ messages <- c(object @ messages , current_messages )
83+ attr(current_code , " id" ) <- sample.int(.Machine $ integer.max , size = 1 )
84+ object @ code <- new_object_code
85+ }
9286
9387 lockEnvironment(object @ env , bindings = TRUE )
9488 object
0 commit comments