[R] [External] alist() and missing variables

iuke-tier@ey m@iii@g oii uiow@@edu iuke-tier@ey m@iii@g oii uiow@@edu
Mon May 2 22:07:39 CEST 2022


On Mon, 2 May 2022, Ivan Krylov wrote:

> Hi,
>
> I've been playing around with formals() and stumbled upon some
> behaviour which surprised me:
>
> a <- alist(x=)
> .Internal(inspect(a$x))
> # @55b0ebae67b0 01 SYMSXP g0c0 [MARK,REF(5761)] "" (has value)
> x <- a$x
> .Internal(inspect(x))
> # Error: argument "x" is missing, with no default
> missing(x)
> [1] TRUE
>
> Apparently, the elements corresponding to formal arguments without a
> default value can be passed to functions as arguments (and look like
> empty symbols, which can't be created by as.symbol()), but when
> assigned to a variable, they turn missing and can't be accessed.
>
> How can I safely detect and work with such values?

You can detect them as you did here using missing(). This is what the
byte code compiler implementation does.
[https://homepage.stat.uiowa.edu/~luke/R/compiler/compiler.pdf]

It's not ideal but it's what we have and not likely to change any time
soon.

Best,

luke

>
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney using uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



More information about the R-help mailing list