yihui / xfun

Miscellaneous R functions
https://yihui.org/xfun/
Other
141 stars 28 forks source link

Add a function to test for installed package with min version #45

Closed cderv closed 3 years ago

cderv commented 3 years ago

I think this will be needed more in the future and xfun::loadable() don't have a test on the min version.

This is what is used in shiny and now rmarkdown

# a la shiny:::is_available
is_available <- function(package, version = NULL) {
  installed <- nzchar(system.file(package = package))
  if (is.null(version)) {
    return(installed)
  }
  installed && isTRUE(utils::packageVersion(package) >= version)
}

Should be a new function or an adaptation of xfun::loadable()

yihui commented 3 years ago

Done (pkg_available()). Thanks!

cderv commented 3 years ago

So efficient ! It was mainly as a reminder to add it... when we have time ! 😅

But it was easy enough and so the quicker the better ! Why report to later ? 😄

Thanks!