Re: [R] S4 class and Package NAMESPACE [NC]

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Fri, 25 Jul 2008 08:58:34 -0700

Sylvain ARCHENAULT wrote:
> Hello,
>
> I am trying to make a R package with S4 classes. To do so, i do as usual
> (when no S4 were involved, i.e without NAMESPACE file) and I've got errors
> in class refering to other classes in the package.

Probably because the files are collated in such a way that some classes are referenced (in other class definitions or methods) before they are defined? You can use the Collate: field in DESCRIPTION, or adopt a convention such as defining all classes (in a sensible way) in a file such as AllClasses.R (which happens to collate early).

> So I use a NAMESPACE file to declare classes, it works fine, but now I
> have to declare each functions in the NAMESPACE file. Since I have a lot
> of functions, it's not very easy.

My strategy is to

exportPattern("^[^\\.]")

in NAMESPACE, and use .funcName to mark functions that I don't want to export. This exports the generics and implicitly the methods defined on those generics. If you define methods on generics from other packages, then it's necessary to

exportMethods

an exportMethodsPattern might be a useful addition (either to my knowledge or to R).

Hope that helps

Martin
>
> Is there a way to exports all methods in one statement ? or is there a
> tool which can help generating the NAMESPACE file ?
>
> Thanks for your help,
> Sylvain.
>
> PS: Could you please CC me in your replies since I do not subscribe to the
> list.
> *************************************************************************
> This message and any attachments (the "message") are con...{{dropped:15}}
>
> ______________________________________________
> 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.

-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M2 B169
Phone: (206) 667-2793

______________________________________________
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.
Received on Fri 25 Jul 2008 - 16:00:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jul 2008 - 16:32:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive