[R] substitute in a list
Stéphane Dray
stephane.dray at univ-lyon1.fr
Thu Dec 6 17:32:38 CET 2012
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
--
Stéphane DRAY (stephane.dray at univ-lyon1.fr)
Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - Lyon I
43, Bd du 11 Novembre 1918, 69622 Villeurbanne Cedex, France
Tel: 33 4 72 43 27 57 Fax: 33 4 72 43 13 88
http://pbil.univ-lyon1.fr/members/dray/
More information about the R-help
mailing list