r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
502 stars 139 forks source link

"Replace is not a multiple of replacement length" warning in `is_installed()` and `check_installed()` #1694

Open ddsjoberg opened 7 months ago

ddsjoberg commented 7 months ago

Hello! I am using is_installed() and check_installed() in a pkg and they are great, thank you!

I noticed in the case where you want to check multiple packages AND you specify both version and compare arguments AND there is a mix of versions to check and no version to check, you get an unexpected warning. (A bit of an edge edge case.)

Example below! If you'd like, I can investigate and submit a PR. But I know sometimes it's just easier to update as the maintainer 😝

Thank you!

packageVersion("rlang")
#> [1] '1.1.3'

# throws a warning unexpectedly
rlang::is_installed(
  pkg = c("dplyr", "tidyr"),
  version = c("1.0.0", NA_character_),
  compare = c(">=", NA_character_)
)
#> Warning in info$cmp[has_version] <- compare: number of items to replace is not
#> a multiple of replacement length
#> [1] TRUE

# similar situation, but no warning
rlang::is_installed(pkg = "tidyr", version = NA_character_, compare = NA_character_)
#> [1] TRUE

# when version/compare fully specified, no warning
rlang::is_installed(
  pkg = c("dplyr", "tidyr"),
  version = c("1.0.0", "1.0.0"),
  compare = c(">=", ">=")
)
#> [1] TRUE

Created on 2024-03-03 with reprex v2.1.0