From maechler at stat.math.ethz.ch  Thu Jan 10 10:44:46 2013
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Thu, 10 Jan 2013 10:44:46 +0100
Subject: [Rd] "Default" accessor in S4 classes
In-Reply-To: <7BE26BCC-F7A3-428B-9833-E6EFEA83BCF0@warwick.ac.uk>
References: <50E5D72E.5010704@r-project.org>
	<35A75ECB-EDAD-4FCA-A6D6-4CBD69A163EF@warwick.ac.uk>
	<61D0EF8F-C6B9-4D83-93BC-31386A314958@r-project.org>
	<7BE26BCC-F7A3-428B-9833-E6EFEA83BCF0@warwick.ac.uk>
Message-ID: <20718.36238.52384.86543@stat.math.ethz.ch>

>>>>> Chris Jewell <chris.jewell at warwick.ac.uk>
>>>>>     on Wed, 9 Jan 2013 13:28:49 +1300 writes:
>>>>> "CJ" == Chris Jewell <chris.jewell at warwick.ac.uk>
>>>>>     on Wed, 9 Jan 2013 13:28:49 +1300 writes:

    CJ> Okay, thanks for the input, All.  I'd settled on the explicit coercion as.data.frame as well as the myObject[] syntax which makes a lot of sense.  I'd also like to implement an as.double() method.  However, I'm having trouble embedding this into my package.  In the R file I have:

    CJ> setMethod("as.double", "HD5Proxy", function(x) as.double(x[]))

    CJ> and exportMethods(as.double) in my NAMESPACES file.  However, on checking the package, I get an error saying that method "as.double" cannot be found.  I noticed that the setMethod command actually returns a character vector with "as.numeric", so I'm assuming this is the problem.  How do I explicitly export my as.double method?

As you've noticed above,  `` R prefers as.numeric ''
and that is what you should be dealing with instead :
It's unsatisfactory I agree, but that's what it currently is:

setMethod("as.numeric", ....

and exportMethods(as.numeric)

Martin



[Rd] "Default" accessor in S4 classes
Martin Maechler