[Rd] Missing argument error message

From: Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk>
Date: Thu, 28 Jan 2010 12:57:24 +0000

Back in the days of R 2.6, if you did this, you got this:

> z=function(x){x*2}
> z()

Error in z() : argument "x" is missing, with no default

 But now in this decade we get (for R 2.9 and 2.10):

> z=function(x){x*2}
> z()

Error in z() :
  element 1 is empty;
   the part of the args list of '*' being evaluated was:    (x, 2)

Now I can see (after thinking about it) that what is happening is that because of lazy evaluation or something the 'x' isn't getting spotted as being empty until R tries to do x*2, which obviously maps to *(x,2) in functional form. It's perfectly correct to say element 1 of the args list of '*', being (x,2), is empty.

But which of those two errors above is clearer? I don't suppose much can be done about this since it is going to the guts of modern R, and I was surprised my initial searches didn't find hordes of confused newbies. Just me then. It got me when I was doing a histogram of some dates:

> hist(cases)

Error in inherits(breaks, "POSIXt") :
  element 1 is empty;
   the part of the args list of '.Internal' being evaluated was:    (x, what, which)

 who what which? If the error had been "Error in hist(cases): argument 'breaks' is missing, with no default" you wouldn't be wasting your time reading this now...


blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman

R-devel_at_r-project.org mailing list
Received on Thu 28 Jan 2010 - 13:00:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Jan 2010 - 14:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive