usethis
usethis copied to clipboard
Unexpected behavior of `use_dependence(package, ...)` if package is `"LinkingTo"`-dependence
The if
-clause in the following snippet does not test what the comment above describes, as it can very well be that there are existing dependencies not of the type "LinkingTo"
. If any(is_linking_to) == TRUE
, dependencies would not be moved as they would if any(is_linking_to) == FALSE
.
https://github.com/r-lib/usethis/blob/b0318bf7cadd25797ae97301893923933207c5ca/R/helpers.R#L31-L39
Given a DESCRIPTION
(without SomePackage
in the LinkingTo
-field)
...
Suggests: SomePackage
...
the command use_dependency("SomePackage, "Imports")
. Will move the dependency such that
...
+ Imports: SomePackage
- Suggests: SomePackage
...
However, given a DESCRIPTION
...
Suggests: SomePackage
LinkingTo: SomePackage
...
the command use_dependency("SomePackage, "Imports")
. Will not move the dependency such that
...
+ Imports: SomePackage
Suggests: SomePackage
LinkingTo: SomePackage
...
Admittedly, this is a corner case. I guess the original intention was to add dependencies directly if there are no existing dependencies towards the given package or if the only current dependency toward the given package is of type "LinkingTo"
. If that is the case, that condition should be tested in the corresponding if
-clause.
I am happy to provide a PR if wanted.
Reprex
d <- file.path(tempdir(), "junk")
dir.create(d)
usethis::create_package(path = d, check_name = FALSE)
#> ✔ Setting active project to '/private/var/folders/l8/2cbkmwpx5r3fpptwzcf4syyr0000gn/T/RtmpUVpW1A/junk'
#> ✔ Creating 'R/'
#> ✔ Writing 'DESCRIPTION'
#> Package: junk
#> Title: What the Package Does (One Line, Title Case)
#> Version: 0.0.0.9000
#> Authors@R (parsed):
#> * First Last <[email protected]> [aut, cre] (YOUR-ORCID-ID)
#> Description: What the package does (one paragraph).
#> License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
#> license
#> Encoding: UTF-8
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 7.2.0
#> ✔ Writing 'NAMESPACE'
#> ✔ Setting active project to '<no active project>'
setwd (d)
usethis::use_package("Rcpp", "LinkingTo")
#> ✔ Setting active project to '/private/var/folders/l8/2cbkmwpx5r3fpptwzcf4syyr0000gn/T/RtmpUVpW1A/junk'
#> ✔ Adding 'Rcpp' to LinkingTo field in DESCRIPTION
#> • Possible includes are:
#> #include <Rcpp.h>
#> • #include <RcppCommon.h>
usethis::use_package("Rcpp", "Enhances")
#> ✔ Adding 'Rcpp' to Enhances field in DESCRIPTION
usethis::use_package("Rcpp", "Suggests")
#> ✔ Adding 'Rcpp' to Suggests field in DESCRIPTION
#> • Use `requireNamespace("Rcpp", quietly = TRUE)` to test if package is installed
#> • Then directly refer to functions with `Rcpp::fun()`
usethis::use_package("Rcpp", "Imports")
#> ✔ Adding 'Rcpp' to Imports field in DESCRIPTION
#> • Refer to functions with `Rcpp::fun()`
desc::desc()
#> Package: junk
#> Title: What the Package Does (One Line, Title Case)
#> Version: 0.0.0.9000
#> Authors@R (parsed):
#> * First Last <[email protected]> [aut, cre] (YOUR-ORCID-ID)
#> Description: What the package does (one paragraph).
#> License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
#> license
#> Imports:
#> Rcpp
#> Suggests:
#> Rcpp
#> Enhances:
#> Rcpp
#> LinkingTo:
#> Rcpp
#> Encoding: UTF-8
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 7.2.0
Created on 2022-06-16 by the reprex package (v2.0.1)
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.2.0 (2022-04-22)
#> os macOS Monterey 12.4
#> system aarch64, darwin20
#> ui X11
#> language (EN)
#> collate de_DE.UTF-8
#> ctype de_DE.UTF-8
#> tz Europe/Berlin
#> date 2022-06-16
#> pandoc 2.17.1.1 @ /Applications/RStudio.app/Contents/MacOS/quarto/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> cli 3.3.0 2022-04-25 [1] CRAN (R 4.2.0)
#> crayon 1.5.1 2022-03-26 [1] CRAN (R 4.2.0)
#> desc 1.4.1 2022-03-06 [1] CRAN (R 4.2.0)
#> digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0)
#> evaluate 0.15 2022-02-18 [1] CRAN (R 4.2.0)
#> fansi 1.0.3 2022-03-24 [1] CRAN (R 4.2.0)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0)
#> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.0)
#> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.2.0)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.2.0)
#> knitr 1.39 2022-04-26 [1] CRAN (R 4.2.0)
#> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.2.0)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0)
#> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.2.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.0)
#> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.2.0)
#> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.2.0)
#> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.2.0)
#> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.2.0)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0)
#> Rcpp 1.0.8.3 2022-03-17 [1] CRAN (R 4.2.0)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.2.0)
#> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.2.0)
#> rmarkdown 2.14 2022-04-25 [1] CRAN (R 4.2.0)
#> roxygen2 7.2.0 2022-05-13 [1] CRAN (R 4.2.0)
#> rprojroot 2.0.3 2022-04-02 [1] CRAN (R 4.2.0)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.0)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0)
#> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.2.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.2.0)
#> styler 1.7.0 2022-03-13 [1] CRAN (R 4.2.0)
#> tibble 3.1.7 2022-05-03 [1] CRAN (R 4.2.0)
#> usethis 2.1.6 2022-05-25 [1] CRAN (R 4.2.0)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0)
#> vctrs 0.4.1 2022-04-13 [1] CRAN (R 4.2.0)
#> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0)
#> xfun 0.31 2022-05-10 [1] CRAN (R 4.2.0)
#> xml2 1.3.3 2021-11-30 [1] CRAN (R 4.2.0)
#> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.0)
#>
#> [1] /Users/henriksloot/Library/R/aarch64-apple-darwin20/4.2
#> [2] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#>
#> ──────────────────────────────────────────────────────────────────────────────