32
32
# ' @export
33
33
setGeneric ("eval_code ", function(object, code, cache = FALSE, ...) standardGeneric("eval_code"))
34
34
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
36
38
parsed_code <- parse(text = code , keep.source = TRUE )
37
39
object @ .xData <- rlang :: env_clone(object @ .xData , parent = parent.env(.GlobalEnv ))
38
40
if (length(parsed_code ) == 0 ) {
@@ -51,7 +53,7 @@ setMethod("eval_code", signature = c("qenv", "character"), function(object, code
51
53
tryCatch(
52
54
{
53
55
out <- eval(current_call , envir = object @ .xData )
54
- if (cache && i == seq_along (code_split )) {
56
+ if (cache && i == length (code_split )) {
55
57
attr(current_code , " cache" ) <- out
56
58
}
57
59
if (! identical(parent.env(object @ .xData ), parent.env(.GlobalEnv ))) {
@@ -94,11 +96,9 @@ setMethod("eval_code", signature = c("qenv", "character"), function(object, code
94
96
object
95
97
})
96
98
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
- })
100
99
101
100
setMethod ("eval_code ", signature = c("qenv", "expression"), function(object, code, cache = FALSE, ...) {
101
+ logger :: log_fatal(" eval_code with expression" )
102
102
srcref <- attr(code , " wholeSrcref" )
103
103
if (length(srcref )) {
104
104
eval_code(object , code = paste(attr(code , " wholeSrcref" ), collapse = " \n " ))
@@ -114,6 +114,18 @@ setMethod("eval_code", signature = c("qenv", "expression"), function(object, cod
114
114
}
115
115
})
116
116
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
+
117
129
setMethod ("eval_code ", signature = c("qenv.error", "ANY"), function(object, code, cache = FALSE, ...) {
118
130
object
119
131
})
0 commit comments