Match.call evaluation very lazy

I have the following function:

d <- 4

test <- function(...){
  testc <- match.call(expand.dots = TRUE)$c
}

result <- test(c=d)
result

yields result = d. Normally I would expect by assigning d <- 4 that the result would be result = 4.

What am i doing wrong here?

perhaps something along these lines using rlang ?

d <- 4 
library(rlang)
library(purrr)

test2 <- function(...,env=caller_env()){
 dots <- enquos(...)
 map(dots,
     ~eval_tidy(expr = ., env = env))
}

r2 <- test2(c=1,d=d)
r2
1 Like

Yes, that is how match.call works. If you want the evaluated value of d, you have to eval it:

test <- function(...){
  testc <- match.call(expand.dots = TRUE)$c
  eval.parent(testc)
}
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.