0

I created a package that with many functions that use a period to separate words. For example, I have functions named collapse.chapters(), update.files(), and create.title().

However, when I created the package, some are reported as S3methods (in NAMESPACE, S3method(collapse,chapters)) while others are reported as generic functions (export(create.title)). As a result, I can call create.title() with no issue when the package is attached, but I cannot call collapse.chapters() directly. If I call it directly, R returns,

Error: could not find function 'collapse.chapters',"

though I can call it using packagename:::collapse.chapters().

Is there any way to ensure that the functions are not created as S3 methods?

A very similar question was asked before, but the answer was not entirely clear and my results are slightly different. From those answers, my guess is that R is interpreting the period in SOME of the functions as an indication of a property of an object. The complete list of S3 methods created is

S3method(collapse,chapters)
S3method(collapse,content)
S3method(collapse,definition)
S3method(collapse,html)
S3method(collapse,methods)
S3method(collapse,multicontent)
S3method(collapse,page)
S3method(collapse,section)
S3method(collapse,summary)
S3method(collapse,tags)
S3method(collapse,term)
S3method(collapse,terms)
S3method(update,files)
S3method(update,index)
S3method(start,notation)
Community
  • 1
  • 1
  • What is your goal? Did you define a generic `collapse()` function? Are you intending to create S3methods? Typically those are "hidden" so you could just call `collapse()` on a `chapter` object rather than calling `collapse.chapter()` directory. If you are not trying to create genetic methods, you should probably avoid using `.` in your function names. It's technically allowed but it is just confusing. Are you use `roxygen` or something to create your package? – MrFlick Jul 29 '16 at 17:37
  • 1) All of the functions are generic functions. They are not related to any classes. So "collapse.chapters()" and "collapse.content()" are just two distinct functions. 2) I am using roxygen2. 3) I realize I may be better off using humpback notation or underscores. I have just spent enough time using those functions prior to putting them in a package that I'd like to avoid having to recode everything if possible. – Simon Brauer Jul 29 '16 at 17:41
  • 1
    Does your package have `collapse` function? If so, how is it defined? Want to see what you get by `packagename:::collapse` – Kota Mori Jul 29 '16 at 17:43
  • That first statement seems contradictory. "Generic" has a very special meaning with respect to S3 classes. [see here](http://adv-r.had.co.nz/S3.html). Is that what you mean by "generic"? If not, again, using `.` in your function names is misleading. And i'm guessing that you are using `roxygen` though you still haven't clarified how you are building your NAMESPACE file. It will get confused if there is another function name `collapse` elsewhere. You can save yourself trouble by either manually editing your exports or just use `_` or something rather than `.`. – MrFlick Jul 29 '16 at 17:45
  • before I forget, S3 section of the link https://cran.r-project.org/web/packages/roxygen2/vignettes/rd.html should be useful. – Kota Mori Jul 29 '16 at 17:48
  • 1) My package does not have a "collapse()" function. However, it does rely on dplyr which does. My collapse functions are not meant to be connected to it, though. 2) I am probably not using "generic" in the way they describe in the link. My apologies. What I mean (which may still be an incorrect way of saying it) is a function that is not tied to a class (i.e. is not a method). – Simon Brauer Jul 29 '16 at 17:57
  • Thank you, MrFlick. That solved it. – Simon Brauer Jul 29 '16 at 18:27

0 Answers0