5

I am creating a R-package and I am at the step where I BUILD the package.

I have read the Writing R Extensions documentation about NAMESPACE (more specifically the sections 1.5.1 and 1.5.2 on import, export and on registering S3method).

I am worrying about this step because when I CHECKmy package I got this warning:

Found the following apparent S3 methods exported but not registered: print.myClass print.myOtherClass summary.myClass summary.myOtherClass See section 'Registering S3 methods' in the 'Writing R Extensions' manual.

Any help in deciphering what are the consequences of not registering a S3method and about the NAMESPACE file in general would make my day.

Thanks for your help.

Alex Fortin
  • 2,105
  • 1
  • 18
  • 27

1 Answers1

8

I would bet 10:1 that you wrote something like

export(print.myClass)

in the namespace. Instead, you need to write

S3method(print, myClass)
Cliff AB
  • 1,160
  • 8
  • 15
  • Thanks Cliff, I did found out that the "correct" way of registering a method is by adding `S3method(print, myClass)` in the NAMESPACE file. Would you know what it does to register a method? It looks like my package is working just fine without registering them. Also, would you have a tip for me as to how to go about registering all of my methods ? At the moment, I am editing NAMESPACE using notepad and I can't believe there is no better way of doing this. – Alex Fortin May 26 '15 at 17:24
  • Okay, I have found this helpful [link](http://cran.r-project.org/web/packages/roxygen2/vignettes/namespace.html). I still do not have a clear picture of what's going on but it's getting there. – Alex Fortin May 26 '15 at 17:45
  • 1
    As I'm sure you know, if you don't export objects, users will not have access to them. S3methods are exported slightly differently and I *think* the reason for this is that R will not complain if you have an S3method with no .Rd file; it's a generic function so you don't need to tell the user what it does. As you've noticed, if you don't include an .Rd file for an exported object, you can still build your package and the user can still use that object. But CRAN will not accept a package that has exported objects with no .Rd files. They will accept a package with S3methods with no .Rd files. – Cliff AB May 26 '15 at 17:52
  • 2
    In terms of doing things in a more efficient manner; I would suggest looking into ROxygen for easier creation of .Rd files, although I don't use it myself. I would be a little concerned if the number of things you are exporting is so large that creating the NAMESPACE file is time consuming: remember that you only need to export things that the user themselves will be using; all of your functions will still have access to objects that are masked. If your package has so many objects that a user directly calls that it's hard for *you* to keep track of them, it may be overwhelming for a user. – Cliff AB May 26 '15 at 17:58
  • To document this appropriately using roxygen, see https://stackoverflow.com/questions/29360132/use-roxygen-to-make-s3method-in-namespace/29639694#29639694 and https://stackoverflow.com/questions/7198758/roxygen2-how-to-properly-document-s3-methods – Martin Smith Jun 05 '20 at 10:24