[R] S3 classes and building a package

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Feb 22 07:58:14 CET 2011


setClass created an S4 class, not an S3 class, and classes are not 
objects (so don't try to use it in package.skeleton). [*]

Are you going to have "buzz" methods for S4 generics?  If not, you 
don't need the setClass line.  If you do, you need to put the line 
yourself in an R file in the package skeleton, one that will be 
sourced before anything which makes use of it (e.g. file AAA.R).

[*] Well, currently creating that class creates object .__C__buzz, but 
if you use package.skeleton without a list, you get
Warning message:
In dump(internalObjs, file = file.path(code_dir, sprintf("%s-internal.R",  :
   deparse of an S4 object will not be source()able

and that object is .__C__buzz.

On Mon, 21 Feb 2011, Laura Smith wrote:

> Hi List!
>
> Suppose I have the following, please:
>
>> setClass("buzz",representation(x="numeric"),S3methods=TRUE)
> [1] "buzz"
>> x <- rnorm(10)
>> class(x) <- "buzz"
>> plot.buzz <- function(x,y,...) {
> + plot.default(x,type="l",col="blue")
> + }
>> f <- function(x) {
> + return(x^2)
> + }
>> package.skeleton(list=c("buzz","plot.buzz","f"),name="test1")
> Creating directories ...
> Creating DESCRIPTION ...
> Creating Read-and-delete-me ...
> Saving functions and data ...
> Making help files ...
> Done.
> Further steps are described in './test1/Read-and-delete-me'.
> Warning message:
> In package.skeleton(list = c("buzz", "plot.buzz", "f"), name = "test1") :
>  object ''buzz'' not found
>>
>
> How can I bring the class "buzz" into the new package, please?
>
> Thank you!
> Laura
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list