[Rd] mget(missingArgument)?

Gabriel Becker g@bembecker @end|ng |rom gm@||@com
Tue Jun 23 05:37:32 CEST 2020


At first I thought this was more or less correct, because

> f = function(x) { y <- mget("x")[[1]]; missing(y)}

> f()

[1] TRUE


reflects the actual "value" of x, but then at the very least this


> f = function(x) { y <- mget("x")[[1]]; y}

> f()

*Error in f() : argument "y" is missing, with no default*


Is a problem because, of course, y was not an argument of f and talking
about its default is nonsensical, and the actual argument which was missing
is not named.


~G

On Mon, Jun 22, 2020 at 5:06 PM William Dunlap via R-devel <
r-devel using r-project.org> wrote:

> Currently, when mget() is used to get the value of a function's argument
> with no default value and no value in the call it returns the empty name
> (R_MissingArg).  Is that the right thing to do or should it return
> 'ifnotfound' or give an error?
>
> E.g.,
> > a <- (function(x) { y <- "y from function's environment";
> mget(c("x","y","z"), envir=environment(), ifnotfound=666)})()
> > str(a)
> List of 3
>  $ x: symbol
>  $ y: chr "y from function's environment"
>  $ z: num 666
>
> The similar function get0() gives an error in that case.
> > b <- (function(x) get0("x", envir=environment(), ifnotfound=666))()
> Error in get0("x", envir = environment(), ifnotfound = 666) :
>   argument "x" is missing, with no default
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



More information about the R-devel mailing list