[Rd] Missing argument error message

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Jan 28 13:57:24 CET 2010


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...

Barry

-- 
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



More information about the R-devel mailing list