@@ -274,6 +274,7 @@ extract_occurrence <- function(pd) {
274274 # What occurs in a function body is not tracked.
275275 x <- pd [! is_in_function(pd ), ]
276276 sym_cond <- which(x $ token %in% c(" SPECIAL" , " SYMBOL" , " SYMBOL_FUNCTION_CALL" ))
277+ sym_fc_cond <- which(x $ token == " SYMBOL_FUNCTION_CALL" )
277278
278279 if (length(sym_cond ) == 0 ) {
279280 return (character (0L ))
@@ -287,28 +288,27 @@ extract_occurrence <- function(pd) {
287288 sym_cond <- setdiff(sym_cond , which(x $ id %in% after_dollar ))
288289 }
289290
290- ass_cond <- grep(" ASSIGN" , x $ token )
291- if (! length(ass_cond )) {
291+ assign_cond <- grep(" ASSIGN" , x $ token )
292+ if (! length(assign_cond )) {
292293 return (c(" <-" , unique(x [sym_cond , " text" ])))
293294 }
294295
295- sym_cond <- sym_cond [sym_cond > ass_cond ] # NOTE 1
296+ # For cases like 'eval(expression(c <- b + 2))' removes 'eval(expression('.
297+ sym_cond <- sym_cond [! (sym_cond < min(assign_cond ) & sym_cond %in% sym_fc_cond )]
298+
296299 # If there was an assignment operation detect direction of it.
297- if (unique(x $ text [ass_cond ]) == " ->" ) { # NOTE 2
300+ if (unique(x $ text [assign_cond ]) == " ->" ) { # What if there are 2 assignments: e.g. a <- b -> c.
298301 sym_cond <- rev(sym_cond )
299302 }
300303
301- after <- match(min(x $ id [ass_cond ]), sort(x $ id [c(min(ass_cond ), sym_cond )])) - 1
304+ after <- match(min(x $ id [assign_cond ]), sort(x $ id [c(min(assign_cond ), sym_cond )])) - 1
302305 ans <- append(x [sym_cond , " text" ], " <-" , after = max(1 , after ))
303306 roll <- in_parenthesis(pd )
304307 if (length(roll )) {
305308 c(setdiff(ans , roll ), roll )
306309 } else {
307310 ans
308311 }
309-
310- # ## NOTE 2: What if there are 2 assignments: e.g. a <- b -> c.
311- # ## NOTE 1: For cases like 'eval(expression(b <- b + 2))' removes 'eval(expression('.
312312}
313313
314314# ' Extract side effects
0 commit comments