[Rd] Creating a reference class object from a class definition in a package fails

Jeffrey Horner jeffrey.horner at gmail.com
Thu Feb 3 22:46:19 CET 2011


Apparently reference classes must be declared in the NAMESPACE file
via an S4 declaration. If I place the following in the NAMESPACE file
all is well:

exportClasses(TestClass)
export(TestClass)


Jeff

On Wed, Feb 2, 2011 at 9:25 PM, Jeffrey Horner <jeffrey.horner at gmail.com> wrote:
> Hi,
>
> I'm trying to create a package that contains reference class
> definitions from which users can create reference objects, but there
> seems to be something awry.
>
> My toy example creates an empty package via
> package.skeleton('TestClass') to which I add the following R code:
>
> TestClass <- setRefClass('TestClass',fields=c('name'))
>
> Unfortunately my R console output bears this:
>
>> library(TestClass)
>> TestClass$new(name='foo')
> Error: attempt to apply non-function
>> getRefClass('TestClass')$new(name='foo')
> Error: attempt to apply non-function
>
> Creating the same reference class in the global environment works though:
>
>> x <- setRefClass('TestClass',fields='name')
>> x$new(name='foo')
> An object of class "TestClass"
> <environment: 0x82a43cc>
>
> I'm new to S4 and reference classes, so maybe I'm missing something fundamental?
>
> Jeff
>
>> sessionInfo()
> R version 2.13.0 Under development (unstable) (2011-02-02 r54197)
> Platform: i686-pc-linux-gnu (32-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices datasets  utils     methods   base
>
> other attached packages:
> [1] TestClass_1.0
>
> loaded via a namespace (and not attached):
> [1] tools_2.13.0
>



-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner



More information about the R-devel mailing list