[Rd] Assigning empty symbol to variable.

luke-tierney at uiowa.edu luke-tierney at uiowa.edu
Mon Oct 21 22:52:03 CEST 2013


On Mon, 21 Oct 2013, Jeroen Ooms wrote:

> When a variable is assigned the empty symbol, looking up the variable
> results in an error message that looks like a function call:
>
>> foo <- as.list(lm)$data
>> ls()
> [1] "foo"
>> foo
> Error: argument "foo" is missing, with no default
>> get("foo")
> Error in get("foo") : argument "foo" is missing, with no default
>> rm("foo")
>
> I ran into this problem when writing a function to serialize functions by
> their list representation, e.g. as.list(lm). It is quite hard to debug
> because of the confusing error message. I would have expected that:
>
>  foo == substitute()
>
> just like
>
>  as.list(lm)$data == substitute()
>
> Is this intended behaviour?
>
> 	[[alternative HTML version deleted]]

'intended' is probably too strong, but it is a consequence of long-ago
implementation decisions that are buried deeply enough to be hard to
change at this point. Any code that computes on the language and want
to be able to handle missing arguments needs to be aware of this. You
can look at the compiler sources or the woven version to see how it is
handled there.

Best,

luke

>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Chair, Statistics and Actuarial Science
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 at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



More information about the R-devel mailing list