Roxygen thinks a function of mine is an S3 method, and so breaks upon installation of my package
Asked Answered
R

1

13

I'm using roxygen to create my own package. I have a function that's causing a problem:

##' extract.sig.metadata
##' @param foo bar
##' @author me
##' @export
extract.sig.metadata <- function(foo){
# does stuff
}

I've created my package skeleton (with create(my-package) from devtools), and I've used document() to process the roxygen tags. However, when I try to install my package, it fails:

... * installing help indices ** building package indices ** testing if installed package can be loaded Error : object 'extract' not found whilst loading namespace 'my-package' Error: loading failed Execution halted

I'm pretty sure that roxygen thinks that extract.sig.metadata is an S3 method, i.e. a specialized form of export(), but it's not finding the function export(), and so it's breaking. But this isn't an s3 method, it's just a function called extract.sig.metadata. If I look in the Rd code, the /usage tag looks weird:

\usage{
\method{extract}{sig.metadata}(spec.df, var = "product_name",
  ratio.cutoff = 0.001, prob.modifer = 3, frequency.cutoff = NA,
  verbose = F, assign.to.global.env = FALSE, use.bigrams = T, clean = T,
  ngram.dupe.n.cutoff = 0.1, max.obs = 10000)
}

If I do change the name to extractSigMetadata, the problem is technically fixed, and the .Rd code changes,

\usage{
 extractSigMetadata(foo)
}

But I would really like to not have to change the name of my function (there are tens of functions that have the same problem in my package, and they are used in a bunch of scripts - it would be a huge pain to change my naming schema not).

---> Does anyone know how I can tell roxygen that this is just a normal function and not weird s3 method? I'm guessing it has something to do with the @method tag, but I don't know how to use it properly enough to make this work. Thanks!!!

Roentgen answered 26/6, 2014 at 23:7 Comment(2)
Which version of Royxgen are you running? You don't have a generic function named extract, do you?Subnormal
Nope, no generic version of extract, but R.utils did - that's what was causing the problem. However, using @export extract.sig.metadata instead of @export fixes it!Roentgen
R
11

Fixed it!

Using @export extract.sig.metadata instead of @export apparently tells roxygen that extract.sig.metadata is the entire function name, and this fixes the problem. In this particular case, I didn't have a generic extract function, but R.utils (a package that my package did not depend upon but was nevertheless loaded) did have an extract function.

Hope this helps anyone with the same problem in the future. Thanks!

P.S. Hadley suggests better naming practices, which I will attempt to follow in the future.

Roentgen answered 27/6, 2014 at 15:54 Comment(3)
I had this issue happen to me once - my suboptimal solution was to rename the function.Severen
does this still work? @export full.name still gives me \usage{\method{full}{name}, frustratingOrate
For the solution to get rid of the wrong "S3 method for class" usage text in the generated help see: stackoverflow.com/a/24607763Puberty

© 2022 - 2024 — McMap. All rights reserved.