usethis
usethis copied to clipboard
Repeated calls to `use_package(., type = "LinkingTo") may lead to logical error in `use_dependency`
If the only current dependence for package
is of type "LinkingTo"
and use_package(package, "LinkingTo", ...)
is called, the variable is_linking_to
in the following lines evaluates to FALSE
, and the function is not exited in subsequently.
https://github.com/r-lib/usethis/blob/b0318bf7cadd25797ae97301893923933207c5ca/R/helpers.R#L31-L39
Consequently, after the following operation, the variable existing_type
will have zero length. Furthermore, the subsequently defined variable delta
will also have zero length, so the following if
condition will be ill-formed.
https://github.com/r-lib/usethis/blob/b0318bf7cadd25797ae97301893923933207c5ca/R/helpers.R#L41-L43
Possible easy fix would be the following:
if (length(existing_type) > 1) {
existing_type <- setdiff(existing_type, "LinkingTo")
}
This ensures that the code does not change unless the only existing dependency is of type "LinkingTo"
and the type
is also LinkingTo
(for any other case with an existing dependence of type "LinkingTo"
, the function would have been exited earlier).
A realistic scenario where this might occur is when a minimum version of the "LinkingTo"
-dependency has to be updated or set.
I am happy to provide a PR if wanted.
This looks like it might be related to #1329
True; the changes in #1329 appear to be equivalent to my proposed fix.