roxygen2: function not exported to NAMESPACE even after using @export
Asked Answered
V

2

8

I am building a package and get an error, saying that a function is not an exported object of the package. In the R script, I have used @export tag to export the function, however when I roxigenise using document() or roxygen() the function is not exported to the NAMESPACE (the Rmd file for that function is created though).

Vaccination answered 24/10, 2016 at 13:1 Comment(7)
Does your_package:::your_function work after loading your package?Reconnoiter
Yes, it does. However, as I read, it is not suggested to do so @ReconnoiterVaccination
Indeed. Just checking. Are you defining method for some S3 class? Also, it may be useful to post the roxygen block here.Reconnoiter
Yes, I am. Do you mean I should post the R script or the NAMESPACE? @ReconnoiterVaccination
Found the issue. It was a very stupid one. When I wrote the R script there was an additional space before writing the codee. e.g. #' export rather than #' exportVaccination
@Vaccination your comment is confusing as it does not include the @ symbol before export and your comparison looks identical (both have one space). Perhaps this was because of the markdown formatting.Lusatian
This is a helpful thread. For me, the problem was the unticked box 'roxygenise when install and restart'Everetteverette
L
8

I had a similar problem. It turned out that inside my function I had commented out a line that began with an apostrophe (in front of 'Battlestar Galactica' in my fake example) so it look like this:

#' @export
getMyFavoriteSciFiShows <- function() {
  myFavoriteSciFiShows <-
    c('Star Trek Next Generation',
      #'Battlestar Galactica',
      'Babylon 5')
  return(myFavoriteSciFiShows)
}

This really screwed up roxygen2 v 6.0.1 since it did not signal any errors and this is what it put into my NAMSEPACE file:

export("Galactica',")
export(Battlestar)
Lusatian answered 28/2, 2017 at 16:5 Comment(1)
Thanks, this helped me too. My impression is that roxygen attempts to interpret ANY appearance of #' and this often messes up @export and other things.Lawhorn
M
1

It happened to me then I ran

devtools::document()

and click check from the Build tab the problem got solved.

I am giving this answer to someone who may have this same problem and search for this. It may help.

Milburt answered 20/7, 2021 at 19:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.