Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!!!

like image 585
Hillary Sanders Avatar asked Jun 26 '14 23:06

Hillary Sanders


1 Answers

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.

like image 115
Hillary Sanders Avatar answered Oct 19 '22 07:10

Hillary Sanders