From h.wickham at gmail.com  Sun Aug 25 16:29:29 2013
From: h.wickham at gmail.com (Hadley Wickham)
Date: Sun, 25 Aug 2013 09:29:29 -0500
Subject: [Rd] Correct NAMESPACE approach when writing an S3 method for a
 generic in another package
In-Reply-To: <CAAHES9yT-YM=huPWJ+Wgv7y8RQV3n=hX8cHOMYXrCLNc7A4e4g@mail.gmail.com>
References: <CAAHES9yT-YM=huPWJ+Wgv7y8RQV3n=hX8cHOMYXrCLNc7A4e4g@mail.gmail.com>
Message-ID: <CABdHhvG4tWCg1n86mOY5Qd3s_xcmzJ+KsH0npRGoWDnQ4OrEHA@mail.gmail.com>

What I do, which is probably wrong, but at least it works, is export
the s3 method as a function. i.e. instead of

S3method(genericfunction, myclass)

I do

export(genericfunction.myclass)

Hadley

On Fri, Aug 23, 2013 at 11:01 PM, Gavin Simpson <ucfagls at gmail.com> wrote:
> Dear List,
>
> In one of my packages I have an S3 method for the plot3d generic
> function from package rgl. I am trying to streamline my Depends
> entries but don't know how to have
>
> plot3d(foo)
>
> in the examples section for the plot3d method in my package, without
> rgl being in Depends.
>
> Note that I importFrom(rgl, plotd3d) and register my S3 method via
> S3Method() in the NAMESPACE.
>
> If rgl is not in Depends but in Imports, I see this when checking the package
>
>> ## 3D plot of data with curve superimposed
>> plot3d(aber.pc, abernethy2)
> Error: could not find function "plot3d"
>
> I presume this is because rgl's namespace is only loaded but the
> package is not attached to the search path.
>
> Writing R extensions indicates that one can export from a namespace
> something that was imported from another package namespace. I thought
> that might help the situation, and now the code doesn't raise an
> error, I get
>
> * checking for missing documentation entries ... WARNING
> Undocumented code objects:
>   ?plot3d?
> All user-level objects in a package should have documentation entries.
> See the chapter ?Writing R documentation files? in the ?Writing R
> Extensions? manual.
>
> as I don't document plot3d() itself.
>
> What is the recommended combination of Depends and Imports plus
> NAMESPACE directives etc that one should use in this situation? Or am
> I missing something else?
>
> I have a similar issue with my package including an S3 method for a
> generic in the lattice package, so if possible I could get rid of both
> of these from Depends if I can solve the above issue.
>
> Thanks in advance.
>
> Gavin
>
> --
> Gavin Simpson
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Chief Scientist, RStudio
http://had.co.nz/



[Rd] Correct NAMESPACE approach when writing an S3 method for a generic in another package
Hadley Wickham