3232# ' @export
3333setGeneric ("eval_code ", function(object, code, cache = FALSE, ...) standardGeneric("eval_code"))
3434
35- setMethod ("eval_code ", signature = c("qenv", "character"), function(object, code, cache = FALSE, ...) {
35+ setMethod ("eval_code ", signature = c("qenv"), function(object, code, cache = FALSE, ...) {
36+ logger :: log_fatal(" eval_code with ANY" )
37+ code <- .preprocess_code(code ) # preprocess code to ensure it is a character vector
3638 parsed_code <- parse(text = code , keep.source = TRUE )
3739 object @ .xData <- rlang :: env_clone(object @ .xData , parent = parent.env(.GlobalEnv ))
3840 if (length(parsed_code ) == 0 ) {
@@ -51,7 +53,7 @@ setMethod("eval_code", signature = c("qenv", "character"), function(object, code
5153 tryCatch(
5254 {
5355 out <- eval(current_call , envir = object @ .xData )
54- if (cache && i == seq_along (code_split )) {
56+ if (cache && i == length (code_split )) {
5557 attr(current_code , " cache" ) <- out
5658 }
5759 if (! identical(parent.env(object @ .xData ), parent.env(.GlobalEnv ))) {
@@ -94,11 +96,9 @@ setMethod("eval_code", signature = c("qenv", "character"), function(object, code
9496 object
9597})
9698
97- setMethod ("eval_code ", signature = c("qenv", "language"), function(object, code, cache = FALSE, ...) {
98- eval_code(object , code = paste(vapply(lang2calls(code ), deparse1 , collapse = " \n " , character (1L )), collapse = " \n " ))
99- })
10099
101100setMethod ("eval_code ", signature = c("qenv", "expression"), function(object, code, cache = FALSE, ...) {
101+ logger :: log_fatal(" eval_code with expression" )
102102 srcref <- attr(code , " wholeSrcref" )
103103 if (length(srcref )) {
104104 eval_code(object , code = paste(attr(code , " wholeSrcref" ), collapse = " \n " ))
@@ -114,6 +114,18 @@ setMethod("eval_code", signature = c("qenv", "expression"), function(object, cod
114114 }
115115})
116116
117+ setGeneric (".preprocess_code ", function(code) standardGeneric(".preprocess_code"))
118+
119+ setMethod (".preprocess_code ", signature = c("ANY"), function(code) {
120+ logger :: log_warn(" process character" )
121+ as.character(code )
122+ })
123+
124+ setMethod (".preprocess_code ", signature = c("language"), function(code) {
125+ logger :: log_warn(" process language" )
126+ paste(vapply(lang2calls(code ), deparse1 , collapse = " \n " , character (1L )))
127+ })
128+
117129setMethod ("eval_code ", signature = c("qenv.error", "ANY"), function(object, code, cache = FALSE, ...) {
118130 object
119131})
0 commit comments