Skip to content

substitute in a list

1 message · Stéphane Dray

#
Hello,

I would like to use substitute in a list to evaluate the formals 
arguments using the environment define by the arguments list. For instance :

f1 <- function(x, y = 1:x){
   ans <- as.list(match.call())
   ##possible args:
   frmls <- formals(as.character(ans[[1]]))
   ## eval formals locally
   frmls <- lapply(frmls, substitute, env = c(ans[-1], frmls))
   return(c(ans, frmls))
}


f1(3)
## returns
Error in lapply(frmls, substitute, env = c(ans[-1], frmls)) :
   '...' used in an incorrect context

I do not understand why. I would like to obtain something like :

[[1]]
"f1"

$x
3

$y
1:3


Any idea of the problem and what would be the correct way to implement it ?

Thanks in advance