mget(missingArgument)?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

mget(missingArgument)?

R devel mailing list
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]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: mget(missingArgument)?

Gabriel Becker-2
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 <
[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel