NAMESPACE not generated by roxygen2. Skipped. - Confusion with Hadley book
Asked Answered
T

5

45

I am trying to make a package but when I run document() it prints NAMESPACE not generated by roxygen2. Skipped. I am trying to use ggplot2,XML, R6 packages in my functions. I am importing them in the following way:

#' @rdname visualization
#' @param hist_data A table of weather variables with PWS created by hist_data function
#' @param variable A character string of variable name
#' @examples
#' table <- getWeather(city = "San Francisco", state="CA")
#' please <- getConditionsTable(table, "2015-03-09")
#' tab <- hist_data(table, please)
#' head(tab)
#' plot_variable_across_all_pws(hist_data=tab, variable="tempi")
#' @import ggplot2
#' @import XML
#' @import R6

I am wondering what might be causing this error and there is nothing in my Namespace except for exportPattern("^[^\\.]")

Also, I was going over R packages book by Hadley http://r-pkgs.had.co.nz/namespace.html And confused by the line :

"Note that you can choose to use roxygen2 to generate just NAMESPACE, just man/*.Rd, or both. If you don’t use any namespace related tags, roxygen2 won’t touch NAMESPACE. If you don’t use any documentation related tags, roxygen2 won’t touch man/."

Is this what I'm doing wrong? or missing?

Tilly answered 19/3, 2015 at 1:55 Comment(1)
Have you tried putting the imports in the DESCRIPTION file instead? roxygen2 doesn't ever touch that fileHaerr
A
57
  1. Backup NAMESPACE file, if you need it for future use
  2. Delete the NAMESPACE file
  3. Run devtools::document(), so that roxygen2 will generate new NAMESPACE file in the package source directory

*** make sure you have @export tag in the roxygen2 doc section of the R source file.

Aracelis answered 28/12, 2015 at 20:40 Comment(0)
A
17

I think that devtools tries to avoid overwriting DESCRIPTION and NAMESPACE files that it didn't generate itself (to avoid angst if you have meticulously typed them in yourself, instead of using embedded roxygen comments in your r code). It isn't always possible but it tries.

The main mechanism, as I understand it, is to post a comment at the top of the file when it generates the file, and then later on, look for that comment (there are tricky bits round the edge, for example if you use @includes to create the Collate order in the DESCRIPTION file, but I don't think that is your problem here.)

An example of such a comment is

# Generated by roxygen2 (4.1.0.9001): do not edit by hand

The not generated by ... message is alerting you to this, and letting you know devtools is not going to use roxygen2 to make a NAMESPACE file for you. You possibly have the one you mention without the comment because you used RStudio to start your package, rather than devtools::create() ?

If you just delete the NAMESPACE file, I think devtools::document() would then work for you.

BTW You have a typo in the example code above (you have#' @import ggplo2 instead of #' @import ggplot2)

Alvira answered 19/3, 2015 at 2:35 Comment(0)
L
5

Thanks to @jsta's solution and I copied the following line # Generated by roxygen2: do not edit by hand at the top of the NAMESPACE file, and then with an empty line.

Then I ran devtools::document() in the console and it automatically replaced the existing NAMESPACE file.

I think that top line is just what roxygen will look for to see if that file is generated by roxygen.

Lashaun answered 7/9, 2021 at 18:42 Comment(2)
Please don't add "thank you" as an answer. Instead, vote up the answers that you find helpful.Glean
Maybe I didn't make myself clear. It was a modification of someone else's answer, but not entirely the same. @jsta mentioned to copy and paste a file which is generated by roxygen, but I only copy paste the top line of a file. I did upvote the original answer. Besides, I would rather leave a comment instead of posting as an answer, but I don't have enough reputation to do so ;)Lashaun
O
3

None of the preceding examples worked for me. If I deleted the NAMESPACE file then roxygen complained there was no NAMESPACE. If I deleted and re-created a NAMESPACE file (with `touch, e.g. RStudio: Building package with roxygen2. Not producing NAMESPACE file) then roxygen complained that the file was not created with roxygen.

The solution was to copy a NAMESPACE file from another project that was created with roxygen.

Ogive answered 9/2, 2018 at 22:11 Comment(0)
V
2

Also one may simply delete everything from NAMESPACE and add leave one line: exportPattern("^[[:alpha:]]+")

If the file NAMESPACE is changed manually, devtools::document() fails to overwrite this file, that is why it leaves as before. When you delete the text from the NAMESPACE file and insert this line, devtools::document() thinks that the file is new and overwrites it.

Vatic answered 22/9, 2015 at 14:23 Comment(2)
Could you please elaborate more your answer adding a little more description about the solution you provide?Padgett
If the file NAMESPACE is changed manually, devtools::document() fails to overwrite this file, that is why it leaves as before. When you delete the text from the NAMESPACE file and insert this line, devtools::document() thinks that the file is new and overwrites it.Vatic

© 2022 - 2024 — McMap. All rights reserved.