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"> fooError: 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]]
Jeroen, The problem seems to be that you are grabbing a symbol that doesn't have a name. I suspect its R_UnboundValue, but I don't have time to check right now. Anyway, take a look at this:> .Internal(inspect(as.list(lm)$data))@1cada98 01 SYMSXP g1c0 [MARK,NAM(2)] "" (has value) And compare it with this:> x = as.symbol("y") > xy> .Internal(inspect(x))@2204db8 01 SYMSXP g1c0 [MARK,NAM(1)] "y" So you have attemtped to assign a symbol pointing to the variable "" to foo. My guess is that there is a specific way arguments are assigned values within a closure that allows this to happen when a function is being called, which allows for "missing" argument values, but those special mechanisms/protections aren't available outside of that situation using standard assignment mechanics and so R is getting confused. AFAICT the assignment to foo should probably just be failing outright. ~G On Mon, Oct 21, 2013 at 12:31 PM, Jeroen Ooms <jeroen.ooms@stat.ucla.edu>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]] > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Gabriel Becker Graduate Student Statistics Department University of California, Davis [[alternative HTML version deleted]]
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