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-tier...@uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to