[Rd] Missing values for S4 slots

From: Ross Boylan <ross_at_biostat.ucsf.edu>
Date: Fri 24 Nov 2006 - 19:23:14 GMT

Using R 2.4, the following fails:
setClass("testc", representation(a="ANY")) makeC <- function(myarg) new("testc", a=myarg) makeC()
-> Error in initialize(value, ...) : argument "myarg" is missing,

   with no default

On the other hand, this is OK:
f <- function(a) g(b=a)
g <- function(b) if(missing(b)) "missing" else "valid arg" g()
-> "missing"

By the way, new("testc") succeeds.

Is there a good way around this? Since my real example has several 4 arguments that might be missing, testing on missingness and calling "new" with appropriate explicit arguments is not an attractive option.

Passing all the arguments in is also not an option, since my call to "new" includes an argument not in the constructor (i.e., my equivalent of makeC).

I suspect there's something I could do to get the constructor arguments, modify the list (i.e., delete args that were missing and insert new ones), and do.call(new, myArgList). Not only am I unsure how to do that (or if it would work), I'm hoping there's a better way.

What's the best approach to this problem?

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Nov 25 06:25:50 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 24 Nov 2006 - 21:30:45 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.