Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rlang to check if required package versions are installed #665

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Imports:
jsonlite,
openssl (>= 2.0.0),
packrat (>= 0.6),
rlang (>= 1.0.0),
rstudioapi (>= 0.5),
tools,
yaml (>= 2.1.5)
Expand All @@ -38,7 +39,7 @@ Suggests:
withr
License: GPL-2
Encoding: UTF-8
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
URL: https://github.com/rstudio/rsconnect
BugReports: https://github.com/rstudio/rsconnect/issues
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export(tasks)
export(terminateApp)
export(unsetProperty)
export(writeManifest)
import(rlang)
importFrom(stats,na.omit)
importFrom(stats,setNames)
importFrom(utils,available.packages)
Expand Down
16 changes: 0 additions & 16 deletions R/bundle.R
Original file line number Diff line number Diff line change
Expand Up @@ -839,11 +839,6 @@ validatePackageSource <- function(pkg) {
return()
}

hasRequiredDevtools <- function() {
"devtools" %in% .packages(all.available = TRUE) &&
packageVersion("devtools") > "1.3"
}

preservePackageDescriptions <- function(bundleDir) {
# Copy all the DESCRIPTION files we're relying on into packrat/desc.
# That directory will contain one file for each package, e.g.
Expand Down Expand Up @@ -1111,7 +1106,6 @@ snapshotRDependencies <- function(appDir, implicit_dependencies = c(), verbose =
}

addPackratSnapshot <- function(bundleDir, implicit_dependencies = c(), verbose = FALSE) {

logger <- verboseLogger(verbose)

# if we discovered any extra dependencies, write them to a file for packrat to
Expand All @@ -1134,16 +1128,6 @@ addPackratSnapshot <- function(bundleDir, implicit_dependencies = c(), verbose =
}, add = TRUE)
}

# ensure we have an up-to-date packrat lockfile
packratVersion <- packageVersion("packrat")
requiredVersion <- "0.4.6"
if (packratVersion < requiredVersion) {
stop("rsconnect requires version '", requiredVersion, "' of Packrat; ",
"you have version '", packratVersion, "' installed.\n",
"Please install the latest version of Packrat from CRAN with:\n- ",
"install.packages('packrat', type = 'source')")
}

# generate the packrat snapshot
logger("Starting to perform packrat snapshot")
tryCatch({
Expand Down
11 changes: 6 additions & 5 deletions R/deployAPI.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
#' @export
deployAPI <- function(api,
...) {
if (!requireNamespace("plumber") ||
packageVersion("plumber") < "0.3.2") {
stop("Version 0.3.2 or later of the plumber package is required to ",
"deploy plumber APIs.")
}
check_installed(
"plumber",
version = "0.3.2",
reason = "to deploy plumber APIs"
)

if (!file.exists(api)) {
stop("The api at '", api, "' does not exist.")
}
Expand Down
11 changes: 6 additions & 5 deletions R/deployDoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
#' @family Deployment functions
#' @export
deployDoc <- function(doc, ...) {
check_installed(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a functional change, since it will prompt interactive users to install the packages rather than immediately stopping; should we announce it in NEWS.md?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, missed this. I'll add momentarily.

"rmarkdown",
version = "0.5.2",
reason = "to deploy individual R Markdown documents"
)

# validate inputs
if (!file.exists(doc)) {
stop("The document '", doc, "' does not exist.")
}
if (!requireNamespace("rmarkdown") ||
packageVersion("rmarkdown") < "0.5.2") {
stop("Version 0.5.2 or later of the rmarkdown package is required to ",
"deploy individual R Markdown documents.")
}

# get qualified doc
qualified_doc <- normalizePath(doc, winslash = "/")
Expand Down
16 changes: 6 additions & 10 deletions R/deploySite.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,16 @@ deploySite <- function(siteDir = getwd(),
python = NULL,
...) {

check_installed(
"rmarkdown",
version = "0.9.5.3",
reason = "to deploy websites"
)

# switch to siteDir for duration of this function
oldwd <- setwd(siteDir)
on.exit(setwd(oldwd), add = TRUE)

# validate we have the version of rmarkdown required to discover
# whether this directory has a website in it, what it's name
# and content directory are, etc.
rmarkdownVersion <- "0.9.5.3"
if (!requireNamespace("rmarkdown") ||
packageVersion("rmarkdown") < rmarkdownVersion) {
stop("Version ", rmarkdownVersion, " or later of the rmarkdown package ",
"is required to deploy websites.")
}

# validate and normalize siteDir
if (!isStringParam(siteDir))
stop(stringParamErrorMessage("siteDir"))
Expand Down
1 change: 1 addition & 0 deletions R/rsconnect-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#'
#' @name rsconnect-package
#' @aliases rsconnect-package rsconnect
#' @import rlang
#' @docType package
#' @keywords package
NULL
16 changes: 0 additions & 16 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,6 @@ md5.as.string <- function(md5) {
paste(md5, collapse = "")
}

# Returns true if the package is installed and satisfies the version constraint.
isAvailable <- function(package, min_version = NULL) {
installed <- nzchar(system.file(package = package))
if (!installed) {
# Not installed.
return(FALSE)
}
if (is.null(min_version)) {
# No version constraint; installation indicates availability.
return(TRUE)
}
# When installed and we have a version constraint, make sure
# the package has at least that version.
return(utils::packageVersion(package) >= min_version)
}

# Escape characters that have special meaning for extended regular expressions as supported by
# list.files.
#
Expand Down
39 changes: 29 additions & 10 deletions man/rsconnectPackages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.