Bug description
rcompendium::add_dependencies() appears to add importMethodsFrom() directives to the DESCRIPTION file when these imports are generated from roxygen2 tags.
For example, when a package contains a roxygen block with:
#' Package methods imports
#'
#' @name package-method-imports
#' @importMethodsFrom rstan summary
NULL
roxygen2 correctly generates the following entry in NAMESPACE:
importMethodsFrom(rstan, summary)
However, after running rcompendium::add_dependencies(), the DESCRIPTION file may be updated with an invalid dependency entry derived from the full NAMESPACE directive, rather than only the package name rstan.
This can lead to errors such as:
devtools::load_all()
#> Error in `check_installed()` at pkgload/R/package-deps.R:91:3:
#> ! Can't parse version in `pkg`.
#> ✖ Problematic versions:
#> • importMethodsFrom (rstan)
My understanding is that importMethodsFrom(rstan, summary) should only appear in NAMESPACE, while DESCRIPTION should contain only the package dependency:
So the expected behavior would be:
# NAMESPACE
importMethodsFrom(rstan, summary)
# DESCRIPTION
Imports:
rstan
not:
# DESCRIPTION
Imports:
importMethodsFrom(rstan, summary)
or any partially parsed variant of this directive.
Reproducible example
A minimal example is a package that uses an S4 method import via roxygen2.
Create an R file, for example R/import-methods.R, with:
#' Package methods imports
#'
#' @name package-method-imports
#' @importMethodsFrom rstan summary
NULL
Then run:
devtools::document()
rcompendium::add_dependencies()
devtools::load_all()
After rcompendium::add_dependencies(), check the DESCRIPTION file.
Observed behavior:
The DESCRIPTION file appears to receive an invalid dependency entry based on the full importMethodsFrom(...) directive.
This causes devtools::load_all() / pkgload to fail with a dependency parsing error similar to:
Error in `check_installed()` at pkgload/R/package-deps.R:91:3:
! Can't parse version in `pkg`.
✖ Problematic versions:
• importMethodsFrom (rstan)
Expected behavior:
rcompendium::add_dependencies() should add only the package name to DESCRIPTION:
The full directive should remain only in NAMESPACE:
importMethodsFrom(rstan, summary)
The same issue may also apply to other NAMESPACE directives generated from roxygen2 tags, for example:
#importClassesFrom(pkg, ClassName)
#importFrom(pkg, function_name)
The important distinction is that DESCRIPTION should contain package names, optionally with version constraints, but not NAMESPACE import directives.
Details
```r
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 26200)
Matrix products: default
locale:
[1] LC_COLLATE=English_Switzerland.utf8 LC_CTYPE=English_Switzerland.utf8 LC_MONETARY=English_Switzerland.utf8
[4] LC_NUMERIC=C LC_TIME=English_Switzerland.utf8
time zone: Europe/Zurich
tzcode source: internal
attached base packages:
[1] stats graphics grDevices datasets utils methods base
loaded via a namespace (and not attached):
[1] digest_0.6.39 fastmap_1.2.0 xfun_0.57 magrittr_2.0.5 glue_1.8.1 tibble_3.3.1
[7] knitr_1.51 pkgconfig_2.0.3 htmltools_0.5.9 rmarkdown_2.31 lifecycle_1.0.5 cli_3.6.6
[13] vctrs_0.7.3 renv_1.1.5 compiler_4.3.2 rprojroot_2.1.1 purrr_1.2.2 rstudioapi_0.18.0
[19] tools_4.3.2 pillar_1.11.1 evaluate_1.0.5 yaml_2.3.12 rcompendium_1.4 otel_0.2.0
[25] rlang_1.2.0 fs_2.1.0 usethis_3.2.1
Bug description
rcompendium::add_dependencies()appears to addimportMethodsFrom()directives to theDESCRIPTIONfile when these imports are generated from roxygen2 tags.For example, when a package contains a roxygen block with:
roxygen2correctly generates the following entry inNAMESPACE:However, after running
rcompendium::add_dependencies(), theDESCRIPTIONfile may be updated with an invalid dependency entry derived from the full NAMESPACE directive, rather than only the package namerstan.This can lead to errors such as:
My understanding is that
importMethodsFrom(rstan, summary)should only appear inNAMESPACE, whileDESCRIPTIONshould contain only the package dependency:So the expected behavior would be:
not:
or any partially parsed variant of this directive.
Reproducible example
A minimal example is a package that uses an S4 method import via roxygen2.
Create an R file, for example
R/import-methods.R, with:Then run:
After
rcompendium::add_dependencies(), check theDESCRIPTIONfile.Observed behavior:
The
DESCRIPTIONfile appears to receive an invalid dependency entry based on the fullimportMethodsFrom(...)directive.This causes
devtools::load_all()/pkgloadto fail with a dependency parsing error similar to:Expected behavior:
rcompendium::add_dependencies()should add only the package name toDESCRIPTION:The full directive should remain only in
NAMESPACE:The same issue may also apply to other NAMESPACE directives generated from roxygen2 tags, for example:
The important distinction is that
DESCRIPTIONshould contain package names, optionally with version constraints, but not NAMESPACE import directives.Details
```r R version 4.3.2 (2023-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 26200)Matrix products: default
locale:
[1] LC_COLLATE=English_Switzerland.utf8 LC_CTYPE=English_Switzerland.utf8 LC_MONETARY=English_Switzerland.utf8
[4] LC_NUMERIC=C LC_TIME=English_Switzerland.utf8
time zone: Europe/Zurich
tzcode source: internal
attached base packages:
[1] stats graphics grDevices datasets utils methods base
loaded via a namespace (and not attached):
[1] digest_0.6.39 fastmap_1.2.0 xfun_0.57 magrittr_2.0.5 glue_1.8.1 tibble_3.3.1
[7] knitr_1.51 pkgconfig_2.0.3 htmltools_0.5.9 rmarkdown_2.31 lifecycle_1.0.5 cli_3.6.6
[13] vctrs_0.7.3 renv_1.1.5 compiler_4.3.2 rprojroot_2.1.1 purrr_1.2.2 rstudioapi_0.18.0
[19] tools_4.3.2 pillar_1.11.1 evaluate_1.0.5 yaml_2.3.12 rcompendium_1.4 otel_0.2.0
[25] rlang_1.2.0 fs_2.1.0 usethis_3.2.1