Suppose I maintain two packages, call them foo
and bar
. bar
exports a function baz
and foo
imports it in the help.R file using @importFrom
, i.e., in foo/R/help.R there is a line @importFrom bar baz
. When I document
the namespace file is correctly created so it has importFrom(bar,baz)
.
Now suppose, I change the name of baz
to bash
in the bar
package. I update foo/R/help.R to @importFrom bar bash
. When I document
though, the namespace correctly adds importFrom(bar,bash)
but it does not delete importFrom(bar,baz)
so I get errors when running install
.
I am using the clean = TRUE
argument thinking that would clean this as well, but it seems like that only goes to the man files. Am I missing something here? Or is this a bug?
Thanks!
Are you using the latest version of roxygen2? It should recreate the NAMESPACE file from scratch every time.
Yes, I am using roxygen2 v3.0.0
sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics datasets grDevices utils methods base
other attached packages:
[1] plyr_1.8 ...
extrafont_0.15
[25] roxygen2_3.0.0 testthat_0.7.1
[27] devtools_1.4.1
loaded via a namespace (and not attached):
[1] biglm_0.9-1 boot_1.3-9 brew_1.0-6 cluster_1.14.4 codetools_0.2-8
[6] colorspace_1.2-4 corrplot_0.73 data.table_1.8.10 dichromat_2.0-0 digest_0.6.4
[11] evaluate_0.5.1 extrafontdb_1.0 formatR_0.10 Formula_1.1-1 ggplot2_0.9.3.1
[16] gmp_0.5-11 grid_3.0.2 gtable_0.1.2 Hmisc_3.13-0 httr_0.2
[21] knitr_1.5 labeling_0.2 lattice_0.20-24 lubridate_1.3.3 MASS_7.3-29
[26] memoise_0.1 munsell_0.4.2 parallel_3.0.2 proto_0.3-10 R.cache_0.9.0
[31] R.methodsS3_1.5.2 R.oo_1.15.8 R.utils_1.28.4 RColorBrewer_1.0-5 RCurl_1.95-4.1
[36] reshape2_1.2.2 rjson_0.2.13 Rttf2pt1_1.2 scales_0.2.3 splines_3.0.2
[41] stringr_0.6.2 survival_2.37-4 tools_3.0.2 whisker_0.3-2 xtable_1.7-1
Are you sure you don't have another @importFrom x y
elsewhere?
Nothing obvious, but seems like I must have something lingering where I don't expect it. I will keep searching; sorry to be a bother.
I am reopening this issue because I have been able to create a MWE that produces an error associated with @importFrom
(though I am not entirely sure related to my original post).
I constructed a skeleton package with barebones files and only edited the help.R
file, which is very simple:
#' @docType package
#'
#' @importFrom plyr ddply
NULL
When I call document(package_directory, clean = TRUE)
(where package_directory
is a variable holding the path to the package), everything works fine. Now, I change help.R
to:
#' @docType package
#'
#' @importFrom plyr
NULL
and call document(package_directory, clean = TRUE)
, which causes an error, as expected:
Error in asChar(ivars) :
empty name in directive 'importFrom' in 'NAMESPACE' file
Now, lets go back and fix the help.R
so it is back to the original:
#' @docType package
#'
#' @importFrom plyr ddply
NULL
When I call document(package_directory, clean = TRUE)
, I surprisingly still get the error I got when broke help.R
. I would have thought it would have worked fine here because document
ignores the NAMESPACE
file.
An additional twist is that if instead of using document
after breaking things, I use roxygenize
, it works fine.
According to the roxygen
documentation, "If you have a simple package, you can use roxygenise()
, but for anything more complicated, I recommend that you use document()
." So, why does document
not work here but roxygenize
does? And when should each be used?
As for versions, I am up to date:
> sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics datasets grDevices utils methods base
other attached packages:
[1] plyr_1.8.1 extrafont_0.16 roxygen2_3.1.0 testthat_0.8.1 devtools_1.4.1
Ah, the problem is that document()
first needs to run load_all()
to load the package, and once you've broken the namespace there's no way to load it. In this scenario I usually just undo the change in git.
delete the namespace file and do load_all() and then do devtools::docuement(). It should do the work.
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
Most helpful comment
delete the namespace file and do load_all() and then do devtools::docuement(). It should do the work.