From fc6b3cab4b2b2bac76e41b663d69877052b7d4e5 Mon Sep 17 00:00:00 2001 From: Scott Russell Date: Thu, 6 Sep 2018 12:05:54 -0400 Subject: [PATCH] Executed styler against package source Fixes #1851 Added 'styler' to package 'Suggests' --- DESCRIPTION | 1 + R/build-readme.R | 18 +- R/build-site.R | 3 +- R/check-devtools.r | 14 +- R/check-results.R | 13 +- R/check-win.r | 25 +-- R/check.r | 4 +- R/cran.r | 1 - R/create.r | 20 ++- R/decompress.r | 12 +- R/deps.R | 88 +++++---- R/dev-mode.r | 7 +- R/doctor.R | 29 +-- R/git.R | 19 +- R/github.R | 31 ++-- R/infrastructure-git.R | 6 +- R/infrastructure.R | 14 +- R/install-bioc.r | 33 ++-- R/install-bitbucket.r | 23 ++- R/install-cran.r | 5 +- R/install-git.r | 31 ++-- R/install-github.r | 63 ++++--- R/install-gitlab.r | 38 ++-- R/install-remote.R | 72 +++++--- R/install-svn.r | 14 +- R/install-url.r | 5 +- R/install-version.r | 32 ++-- R/install.r | 216 ++++++++++++----------- R/package.r | 2 +- R/pkgbuild.R | 6 +- R/pkgload.R | 6 +- R/r-hub.R | 1 - R/release.r | 131 ++++++++------ R/reload.r | 1 - R/revdep-email.R | 38 ++-- R/revdep-summarise.R | 3 +- R/revdep.R | 17 +- R/run-examples.r | 8 +- R/run-source.r | 5 +- R/session-info.r | 7 +- R/show-news.r | 6 +- R/source.r | 6 +- R/spell-check.R | 2 +- R/system.r | 22 ++- R/test.r | 30 ++-- R/uninstall.r | 1 - R/upload-ftp.r | 4 +- R/utils.r | 26 +-- R/vignette-r.r | 12 +- R/vignettes.r | 9 +- R/zzz.r | 20 +-- tests/testthat/helper-github.R | 8 +- tests/testthat/helper.R | 1 - tests/testthat/test-bioconductor.r | 12 +- tests/testthat/test-build-site.R | 26 +-- tests/testthat/test-examples.R | 6 +- tests/testthat/test-github-connections.R | 84 ++++++--- tests/testthat/test-github.r | 25 +-- tests/testthat/test-install-gitlab.R | 8 +- tests/testthat/test-install-version.R | 11 +- tests/testthat/test-remote-metadata.R | 13 +- tests/testthat/test-remotes.r | 116 +++++++----- tests/testthat/test-uninstall.r | 8 +- tests/testthat/test-update.R | 2 - tests/testthat/test-vignettes.r | 12 +- tests/testthat/testTest/R/dummy.R | 1 + tests/testthat/testUseData/R/a.r | 1 + 67 files changed, 890 insertions(+), 644 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dea625c27..5c52a9b31 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -56,6 +56,7 @@ Suggests: rversions, sessioninfo, spelling (>= 1.1), + styler, testthat (>= 1.0.2), whisker VignetteBuilder: knitr diff --git a/R/build-readme.R b/R/build-readme.R index 134fefb33..3a844e492 100644 --- a/R/build-readme.R +++ b/R/build-readme.R @@ -16,11 +16,16 @@ build_readme <- function(path = ".", quiet = TRUE, ...) { pkg <- as.package(path) - readme_path <- grep(ignore.case = TRUE, value = TRUE, - "readme[.]rmd", - list.files(c(pkg$path, file.path(pkg$path, "inst"), - full.names = TRUE))) - if (length(readme_path) == 0) { return(invisible()) } + readme_path <- grep( + ignore.case = TRUE, value = TRUE, + "readme[.]rmd", + list.files(c(pkg$path, file.path(pkg$path, "inst"), + full.names = TRUE + )) + ) + if (length(readme_path) == 0) { + return(invisible()) + } readme_path <- file.path(pkg$path, readme_path[[1]]) @@ -35,7 +40,8 @@ build_readme <- function(path = ".", quiet = TRUE, ...) { output <- callr::r(build, args = list(pkg_path = pkg$path, readme_path = readme_path, ... = ..., quiet = quiet), - show = TRUE, spinner = FALSE) + show = TRUE, spinner = FALSE + ) invisible(TRUE) } diff --git a/R/build-site.R b/R/build-site.R index 118025e98..fd1f3eb03 100644 --- a/R/build-site.R +++ b/R/build-site.R @@ -21,7 +21,8 @@ build_site <- function(path = ".", quiet = TRUE, ...) { withr::with_temp_libpaths(action = "prefix", code = { install(pkg = pkg$path, upgrade_dependencies = FALSE, reload = FALSE, quiet = quiet) if (isTRUE(quiet)) { - withr::with_output_sink(tempfile(), + withr::with_output_sink( + tempfile(), pkgdown::build_site(pkg = pkg$path, ...) ) } else { diff --git a/R/check-devtools.r b/R/check-devtools.r index 88a27106d..028736b4d 100644 --- a/R/check-devtools.r +++ b/R/check-devtools.r @@ -50,7 +50,8 @@ check_version <- function(pkg = ".") { pkg <- as.package(pkg) ver <- unlist(numeric_version(pkg$version)) - check_status(length(ver) == 3, + check_status( + length(ver) == 3, "version number has three components", paste0("version (", pkg$version, ") should have exactly three components") ) @@ -83,8 +84,9 @@ check_news_md <- function(pkg) { pkg <- as.package(pkg) news_path <- file.path(pkg$path, "NEWS.md") - if (!file.exists(news_path)) + if (!file.exists(news_path)) { return() + } ignore_path <- file.path(pkg$path, ".Rbuildignore") if (!file.exists(ignore_path)) { @@ -94,9 +96,10 @@ check_news_md <- function(pkg) { } has_news <- grepl("NEWS\\.md", ignore_lines, fixed = TRUE) | - grepl("NEWS.md", ignore_lines, fixed = TRUE) + grepl("NEWS.md", ignore_lines, fixed = TRUE) - check_status(!any(has_news), + check_status( + !any(has_news), "NEWS.md is not ignored", "NEWS.md now supported by CRAN and doesn't need to be ignored." ) @@ -110,7 +113,8 @@ check_news_md <- function(pkg) { } check_remotes <- function(pkg) { - check_status(!has_dev_remotes(pkg), + check_status( + !has_dev_remotes(pkg), "DESCRIPTION doesn't have Remotes field", "Remotes field should be removed before CRAN submission." ) diff --git a/R/check-results.R b/R/check-results.R index ab8a54791..032a27b51 100644 --- a/R/check-results.R +++ b/R/check-results.R @@ -9,9 +9,9 @@ parse_check_results <- function(path) { structure( list( - errors = pieces[grepl("... ERROR", pieces, fixed = TRUE)], + errors = pieces[grepl("... ERROR", pieces, fixed = TRUE)], warnings = pieces[grepl("... WARN", pieces, fixed = TRUE)], - notes = pieces[grepl("... NOTE", pieces, fixed = TRUE)] + notes = pieces[grepl("... NOTE", pieces, fixed = TRUE)] ), path = path, class = "check_results" @@ -23,10 +23,10 @@ signal_check_results <- function(x, on = c("none", "error", "warning", "note")) on <- match.arg(on) has_problem <- switch(on, - none = FALSE, - error = has$errors, + none = FALSE, + error = has$errors, warning = has$errors | has$warnings, - note = has$errors | has$warnings | has$notes + note = has$errors | has$warnings | has$notes ) if (has_problem) { @@ -90,8 +90,9 @@ trunc_middle <- function(x, n_max = 25, n_top = 10, n_bottom = 10) { lines <- strsplit(x, "\n", fixed = TRUE)[[1]] nlines <- length(lines) - if (nlines <= n_max) + if (nlines <= n_max) { return(x) + } paste(c( lines[1:n_top], diff --git a/R/check-win.r b/R/check-win.r index 5fb6bb926..bcea75a72 100644 --- a/R/check-win.r +++ b/R/check-win.r @@ -43,14 +43,15 @@ check_win_oldrelease <- function(pkg = ".", args = NULL, quiet = FALSE, ...) { check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelease"), args = NULL, quiet = FALSE, ...) { - pkg <- as.package(pkg) version <- match.arg(version, several.ok = TRUE) if (!quiet) { - message("Building windows version of ", pkg$package, " (", pkg$version, ")", - " for ", paste(version, collapse = ", "), - " with win-builder.r-project.org.\n") + message( + "Building windows version of ", pkg$package, " (", pkg$version, ")", + " for ", paste(version, collapse = ", "), + " with win-builder.r-project.org.\n" + ) if (interactive() && yesno("Email results to ", maintainer(pkg)$email, "?")) { return(invisible()) } @@ -59,15 +60,19 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea built_path <- pkgbuild::build(pkg$path, tempdir(), args = args, quiet = quiet, ...) on.exit(unlink(built_path)) - url <- paste0("ftp://win-builder.r-project.org/", version, "/", - basename(built_path)) + url <- paste0( + "ftp://win-builder.r-project.org/", version, "/", + basename(built_path) + ) lapply(url, upload_ftp, file = built_path) if (!quiet) { - message("[", strftime(Sys.time(), "%I:%M %p (%Y-%m-%d)"), "] ", - "Check ", maintainer(pkg)$email, " for a link to the built package", - if (length(version) > 1) "s" else "", - " in 15-30 mins.") + message( + "[", strftime(Sys.time(), "%I:%M %p (%Y-%m-%d)"), "] ", + "Check ", maintainer(pkg)$email, " for a link to the built package", + if (length(version) > 1) "s" else "", + " in 15-30 mins." + ) } invisible() diff --git a/R/check.r b/R/check.r index 2d01519e5..dd469ff88 100644 --- a/R/check.r +++ b/R/check.r @@ -68,7 +68,6 @@ check <- function(pkg = ".", check_dir = tempdir(), cleanup = TRUE, error_on = c("never", "error", "warning", "note")) { - pkg <- as.package(pkg) withr::local_options(list(warn = 1)) @@ -156,9 +155,8 @@ check <- function(pkg = ".", check_built <- function(path = NULL, cran = TRUE, remote = FALSE, incoming = remote, force_suggests = FALSE, run_dont_test = FALSE, manual = FALSE, args = "--timings", - env_vars = NULL, check_dir = tempdir(), quiet = FALSE, + env_vars = NULL, check_dir = tempdir(), quiet = FALSE, error_on = c("never", "error", "warning", "note")) { - if (missing(error_on) && !interactive()) { error_on <- "warning" } diff --git a/R/cran.r b/R/cran.r index 53966b6f2..f597ab865 100644 --- a/R/cran.r +++ b/R/cran.r @@ -27,7 +27,6 @@ package_url <- function(package, repos, # @param package The name of the package. # @param available A matrix of information about packages. cran_pkg_version <- function(package, available = available.packages()) { - idx <- available[, "Package"] == package if (any(idx)) { as.package_version(available[package, "Version"]) diff --git a/R/create.r b/R/create.r index 579ba1bcc..80375cb77 100644 --- a/R/create.r +++ b/R/create.r @@ -16,22 +16,25 @@ create <- function(path, description = getOption("devtools.desc"), if (!file.exists(path)) { if (!dir.create(path)) { stop("Failed to create package directory '", basename(path), "'", - call. = FALSE) + call. = FALSE + ) } } # if the directory exists but is not empty, bail files <- list.files(path) if (length(files)) { - valid <- length(files) == 1 && tools::file_ext(files) == "Rproj" - if (!valid) + if (!valid) { stop("Directory exists and is not empty", call. = FALSE) + } } path <- normalizePath(path, winslash = "/", mustWork = TRUE) - setup(path = path, description = description, rstudio = rstudio, - check = check, quiet = quiet) + setup( + path = path, description = description, rstudio = rstudio, + check = check, quiet = quiet + ) invisible(TRUE) } @@ -71,7 +74,8 @@ create_description <- function(path = ".", extra = getOption("devtools.desc"), subdir <- file.path(path, c("R", "src", "data")) if (!any(file.exists(subdir))) { stop("'", path, "' does not look like a package: no R/, src/ or data directories", - call. = FALSE) + call. = FALSE + ) } desc <- build_description(extract_package_name(path), extra) @@ -95,7 +99,7 @@ build_description <- function(name, extra = list()) { Version = "0.0.0.9000", "Authors@R" = getOption("devtools.desc.author"), Description = "What the package does (one paragraph).", - Depends = paste0("R (>= ", as.character(getRversion()) ,")"), + Depends = paste0("R (>= ", as.character(getRversion()), ")"), License = getOption("devtools.desc.license"), Suggests = getOption("devtools.desc.suggests"), Encoding = "UTF-8", @@ -137,7 +141,7 @@ create_namespace <- function(path) { if (file.exists(ns_path)) return() cat( - '# Generated by roxygen2: fake comment so roxygen2 overwrites silently.\n', + "# Generated by roxygen2: fake comment so roxygen2 overwrites silently.\n", 'exportPattern("^[^\\\\.]")\n', sep = "", file = ns_path diff --git a/R/decompress.r b/R/decompress.r index ecda0dcea..6eaa575a3 100644 --- a/R/decompress.r +++ b/R/decompress.r @@ -37,8 +37,9 @@ source_pkg <- function(path, subdir = NULL, before_install = NULL) { } # Call before_install for bundles (if provided) - if (!is.null(info$bundle) && !is.null(before_install)) + if (!is.null(info$bundle) && !is.null(before_install)) { before_install(info$bundle, info$pkg_path) + } info$pkg_path } @@ -50,23 +51,20 @@ decompress <- function(src, target) { if (grepl("\\.zip$", src)) { my_unzip(src, target) outdir <- getrootdir(as.vector(utils::unzip(src, list = TRUE)$Name)) - } else if (grepl("\\.tar$", src)) { utils::untar(src, exdir = target) outdir <- getrootdir(utils::untar(src, list = TRUE)) - } else if (grepl("\\.(tar\\.gz|tgz)$", src)) { utils::untar(src, exdir = target, compressed = "gzip") outdir <- getrootdir(utils::untar(src, compressed = "gzip", list = TRUE)) - } else if (grepl("\\.(tar\\.bz2|tbz)$", src)) { utils::untar(src, exdir = target, compressed = "bzip2") outdir <- getrootdir(utils::untar(src, compressed = "bzip2", list = TRUE)) - } else { ext <- gsub("^[^.]*\\.", "", src) stop("Don't know how to decompress files with extension ", ext, - call. = FALSE) + call. = FALSE + ) } file.path(target, outdir) @@ -76,7 +74,7 @@ decompress <- function(src, target) { # Returns everything before the last slash in a filename # getdir("path/to/file") returns "path/to" # getdir("path/to/dir/") returns "path/to/dir" -getdir <- function(path) sub("/[^/]*$", "", path) +getdir <- function(path) sub("/[^/]*$", "", path) # Given a list of files, returns the root (the topmost folder) # getrootdir(c("path/to/file", "path/to/other/thing")) returns "path/to" diff --git a/R/deps.R b/R/deps.R index be5350979..68a094865 100755 --- a/R/deps.R +++ b/R/deps.R @@ -46,9 +46,9 @@ #' } package_deps <- function(pkg, dependencies = NA, repos = getOption("repos"), type = getOption("pkgType")) { - - if (length(repos) == 0) + if (length(repos) == 0) { repos <- character() + } repos[repos == "@CRAN@"] <- cran_mirror() @@ -110,8 +110,9 @@ dev_package_deps <- function(pkg = ".", dependencies = NA, missing_repos <- setdiff(names(bioc_repos), names(repos)) - if (length(missing_repos) > 0) + if (length(missing_repos) > 0) { repos[missing_repos] <- bioc_repos[missing_repos] + } } filter_duplicate_deps( @@ -119,7 +120,8 @@ dev_package_deps <- function(pkg = ".", dependencies = NA, # We set this cache in install() so we can run install_deps() twice without # having to re-query the remotes - installing$remote_deps %||% remote_deps(pkg)) + installing$remote_deps %||% remote_deps(pkg) + ) } filter_duplicate_deps <- function(cran_deps, remote_deps, dependencies) { @@ -156,24 +158,26 @@ compare_versions <- function(inst, remote, is_cran) { return(BEHIND) } } - if (is.na(c)) return(UNAVAILABLE) # not on CRAN - if (is.na(i)) return(UNINSTALLED) # not installed, but on CRAN + if (is.na(c)) return(UNAVAILABLE) # not on CRAN + if (is.na(i)) return(UNINSTALLED) # not installed, but on CRAN i <- package_version(i) c <- package_version(c) if (i < c) { - BEHIND # out of date + BEHIND # out of date } else if (i > c) { - AHEAD # ahead of CRAN + AHEAD # ahead of CRAN } else { - CURRENT # most recent CRAN version + CURRENT # most recent CRAN version } } - vapply(seq_along(inst), + vapply( + seq_along(inst), function(i) compare_var(inst[[i]], remote[[i]], is_cran[[i]]), - integer(1)) + integer(1) + ) } parse_one_remote <- function(x) { @@ -189,8 +193,10 @@ parse_one_remote <- function(x) { stop("Malformed remote specification '", x, "'", call. = FALSE) } fun <- tryCatch(get(paste0(tolower(type), "_remote"), - envir = asNamespace("devtools"), mode = "function", inherits = FALSE), - error = function(e) stop("Unknown remote type: ", type, call. = FALSE)) + envir = asNamespace("devtools"), mode = "function", inherits = FALSE + ), + error = function(e) stop("Unknown remote type: ", type, call. = FALSE) + ) fun(repo) } @@ -226,8 +232,9 @@ remote_deps <- function(pkg) { available = available, diff = diff, stringsAsFactors = FALSE - ), - class = c("package_deps", "data.frame")) + ), + class = c("package_deps", "data.frame") + ) res$remote <- structure(remote, class = "remotes") res @@ -277,10 +284,11 @@ update.package_deps <- function(object, ..., quiet = FALSE, upgrade = TRUE) { if (upgrade) { install_remotes(object$remote[unavailable], ..., quiet = quiet, upgrade = upgrade) } else if (!quiet) { - message(sprintf(ngettext(sum(unavailable), - "Skipping %d unavailable package: %s", - "Skipping %d unavailable packages: %s" - ), sum(unavailable), paste(object$package[unavailable], collapse = ", "))) + message(sprintf(ngettext( + sum(unavailable), + "Skipping %d unavailable package: %s", + "Skipping %d unavailable packages: %s" + ), sum(unavailable), paste(object$package[unavailable], collapse = ", "))) } } @@ -289,10 +297,11 @@ update.package_deps <- function(object, ..., quiet = FALSE, upgrade = TRUE) { if (upgrade) { install_remotes(object$remote[ahead], ..., quiet = quiet, upgrade = upgrade) } else if (!quiet) { - message(sprintf(ngettext(sum(ahead), - "Skipping %d package ahead of CRAN: %s", - "Skipping %d packages ahead of CRAN: %s" - ), sum(ahead), paste(object$package[ahead], collapse = ", "))) + message(sprintf(ngettext( + sum(ahead), + "Skipping %d package ahead of CRAN: %s", + "Skipping %d packages ahead of CRAN: %s" + ), sum(ahead), paste(object$package[ahead], collapse = ", "))) } } @@ -308,17 +317,21 @@ update.package_deps <- function(object, ..., quiet = FALSE, upgrade = TRUE) { install_packages <- function(pkgs, repos = getOption("repos"), type = getOption("pkgType"), ..., dependencies = FALSE, quiet = NULL) { - if (is.null(quiet)) + if (is.null(quiet)) { quiet <- !identical(type, "source") + } - message(sprintf(ngettext(length(pkgs), - "Installing %d package: %s", - "Installing %d packages: %s" - ), length(pkgs), paste(pkgs, collapse = ", "))) + message(sprintf(ngettext( + length(pkgs), + "Installing %d package: %s", + "Installing %d packages: %s" + ), length(pkgs), paste(pkgs, collapse = ", "))) pkgbuild::with_build_tools( - withr::with_options(list("install.packages.compile.from.source" = "never"), - utils::install.packages(pkgs, repos = repos, type = type, + withr::with_options( + list("install.packages.compile.from.source" = "never"), + utils::install.packages(pkgs, + repos = repos, type = type, dependencies = dependencies, quiet = quiet ) ), @@ -328,8 +341,9 @@ install_packages <- function(pkgs, repos = getOption("repos"), find_deps <- function(pkgs, available = available.packages(), top_dep = TRUE, rec_dep = NA, include_pkgs = TRUE) { - if (length(pkgs) == 0 || identical(top_dep, FALSE)) + if (length(pkgs) == 0 || identical(top_dep, FALSE)) { return(character()) + } top_dep <- standardise_dep(top_dep) rec_dep <- standardise_dep(rec_dep) @@ -338,8 +352,10 @@ find_deps <- function(pkgs, available = available.packages(), top_dep = TRUE, top_flat <- unlist(top, use.names = FALSE) if (length(rec_dep) != 0 && length(top_flat) > 0) { - rec <- tools::package_dependencies(top_flat, db = available, which = rec_dep, - recursive = TRUE) + rec <- tools::package_dependencies(top_flat, + db = available, which = rec_dep, + recursive = TRUE + ) rec_flat <- unlist(rec, use.names = FALSE) } else { rec_flat <- character() @@ -382,7 +398,6 @@ standardise_dep <- function(x) { update_packages <- function(pkgs = NULL, dependencies = NA, repos = getOption("repos"), type = getOption("pkgType")) { - if (isTRUE(pkgs)) { pkgs <- installed.packages()[, "Package"] } @@ -397,7 +412,8 @@ update_packages <- function(pkgs = NULL, dependencies = NA, pkgs <- package_deps(pkgs, dependencies = dependencies, repos = repos, - type = type) + type = type + ) update(pkgs) } @@ -417,7 +433,7 @@ parse_additional_repositories <- function(pkg) { } #' @export -`[.remotes` <- function(x,i,...) { +`[.remotes` <- function(x, i, ...) { r <- NextMethod("[") mostattributes(r) <- attributes(x) r diff --git a/R/dev-mode.r b/R/dev-mode.r index e8f9a3416..14328427a 100644 --- a/R/dev-mode.r +++ b/R/dev-mode.r @@ -37,7 +37,9 @@ dev_mode <- local({ if (!is_library(path)) { warning(path, " does not appear to be a library. ", - "Are sure you specified the correct directory?", call. = FALSE) + "Are sure you specified the correct directory?", + call. = FALSE + ) } message("Dev mode: ON") @@ -48,7 +50,6 @@ dev_mode <- local({ .libPaths(c(path, lib_paths)) } else { - message("Dev mode: OFF") options(dev_path = NULL) @@ -62,7 +63,7 @@ dev_mode <- local({ is_library <- function(path) { # empty directories can be libraries - if (length(dir(path)) == 0) return (TRUE) + if (length(dir(path)) == 0) return(TRUE) # otherwise check that the directories are compiled R directories - # i.e. that they contain a Meta directory diff --git a/R/doctor.R b/R/doctor.R index 29d94a387..32cbccb83 100644 --- a/R/doctor.R +++ b/R/doctor.R @@ -89,20 +89,27 @@ dr_github <- function(path = ".") { config <- git2r::config(r) config_names <- names(modifyList(config$global, config$local)) - if (!uses_github(path)) + if (!uses_github(path)) { msg[["github"]] <- " * cannot detect that this repo is connected to GitHub" - if (!("user.name" %in% config_names)) + } + if (!("user.name" %in% config_names)) { msg[["name"]] <- "* user.name config option not set" - if (!("user.email" %in% config_names)) + } + if (!("user.email" %in% config_names)) { msg[["user"]] <- "* user.email config option not set" + } - if (!file.exists("~/.ssh/id_rsa")) + if (!file.exists("~/.ssh/id_rsa")) { msg[["ssh"]] <- "* SSH private key not found" + } - if (identical(Sys.getenv("GITHUB_PAT"), "")) - msg[["PAT"]] <- paste("* GITHUB_PAT environment variable not set", + if (identical(Sys.getenv("GITHUB_PAT"), "")) { + msg[["PAT"]] <- paste( + "* GITHUB_PAT environment variable not set", "(this is not necessary unless you want to install private repos", - "or connect local repos to GitHub)") + "or connect local repos to GitHub)" + ) + } desc_path <- file.path(path, "DESCRIPTION") desc <- read_dcf(desc_path) @@ -111,16 +118,16 @@ dr_github <- function(path = ".") { re <- "https://github.com/(.*?)/(.*)" if (field_empty(desc, "URL")) { - msg[["URL_empty"]] <-"* empty URL field in DESCRIPTION" + msg[["URL_empty"]] <- "* empty URL field in DESCRIPTION" } else if (field_no_re(desc, "URL", re)) { - msg[["URL"]] <-"* no GitHub repo link in URL field in DESCRIPTION" + msg[["URL"]] <- "* no GitHub repo link in URL field in DESCRIPTION" } re <- paste0(re, "/issues") if (field_empty(desc, "BugReports")) { - msg[["BugReports_empty"]] <-"* empty BugReports field in DESCRIPTION" + msg[["BugReports_empty"]] <- "* empty BugReports field in DESCRIPTION" } else if (field_no_re(desc, "BugReports", re)) { - msg[["BugReports"]] <-"* no GitHub Issues link in URL field in DESCRIPTION" + msg[["BugReports"]] <- "* no GitHub Issues link in URL field in DESCRIPTION" } doctor("github", msg) diff --git a/R/git.R b/R/git.R index 3d58092e7..91ac67584 100644 --- a/R/git.R +++ b/R/git.R @@ -47,10 +47,10 @@ git_sync_status <- function(path = ".", check_ahead = TRUE, check_behind = TRUE) c2 <- git2r::lookup(r, git2r::branch_target(upstream)) ab <- git2r::ahead_behind(c1, c2) -# if (ab[1] > 0) -# message(ab[1], " ahead of remote") -# if (ab[2] > 0) -# message(ab[2], " behind remote") + # if (ab[1] > 0) + # message(ab[1], " ahead of remote") + # if (ab[2] > 0) + # message(ab[2], " behind remote") is_ahead <- ab[[1]] != 0 is_behind <- ab[[2]] != 0 @@ -90,7 +90,7 @@ git_branch <- function(path = ".") { r <- git2r::repository(path, discover = TRUE) if (git2r::is_detached(r)) { - return(NULL) + return(NULL) } git2r::repository_head(r)$name @@ -99,8 +99,9 @@ git_branch <- function(path = ".") { # GitHub ------------------------------------------------------------------ uses_github <- function(path = ".") { - if (!uses_git(path)) + if (!uses_git(path)) { return(FALSE) + } r <- git2r::repository(path, discover = TRUE) r_remote_urls <- git2r::remote_url(r) @@ -109,14 +110,16 @@ uses_github <- function(path = ".") { } github_info <- function(path = ".", remote_name = NULL) { - if (!uses_github(path)) + if (!uses_github(path)) { return(github_dummy) + } r <- git2r::repository(path, discover = TRUE) r_remote_urls <- grep("github", remote_urls(r), value = TRUE) - if (!is.null(remote_name) && !remote_name %in% names(r_remote_urls)) + if (!is.null(remote_name) && !remote_name %in% names(r_remote_urls)) { stop("no github-related remote named ", remote_name, " found") + } remote_name <- c(remote_name, "origin", names(r_remote_urls)) x <- r_remote_urls[remote_name] diff --git a/R/github.R b/R/github.R index 6499fa4e7..c2348f4d5 100644 --- a/R/github.R +++ b/R/github.R @@ -22,22 +22,26 @@ github_error <- function(req) { parsed <- tryCatch(jsonlite::fromJSON(text, simplifyVector = FALSE), error = function(e) { list(message = text) - }) + } + ) errors <- vapply(parsed$errors, `[[`, "message", FUN.VALUE = character(1)) structure( list( call = sys.call(-1), - message = paste0(parsed$message, " (", httr::status_code(req), ")\n", + message = paste0( + parsed$message, " (", httr::status_code(req), ")\n", if (length(errors) > 0) { paste("* ", errors, collapse = "\n") - }) - ), class = c("condition", "error", "github_error")) + } + ) + ), + class = c("condition", "error", "github_error") + ) } github_GET <- function(path, ..., pat = github_pat(), host = "https://api.github.com") { - url <- httr::parse_url(host) url$path <- paste(url$path, path, sep = "/") ## May remove line below at release of httr > 1.1.0 @@ -49,7 +53,6 @@ github_GET <- function(path, ..., pat = github_pat(), github_POST <- function(path, body, ..., pat = github_pat(), host = "https://api.github.com") { - url <- httr::parse_url(host) url$path <- paste(url$path, path, sep = "/") ## May remove line below at release of httr > 1.1.0 @@ -65,7 +68,9 @@ github_rate_limit <- function() { reset <- as.POSIXct(core$reset, origin = "1970-01-01") cat(core$remaining, " / ", core$limit, - " (Reset ", strftime(reset, "%H:%M:%S"), ")\n", sep = "") + " (Reset ", strftime(reset, "%H:%M:%S"), ")\n", + sep = "" + ) } github_commit <- function(username, repo, ref = "master") { @@ -92,11 +97,13 @@ github_pat <- function(quiet = TRUE) { return(pat) } if (in_ci()) { - pat <- paste0("b2b7441d", - "aeeb010b", - "1df26f1f6", - "0a7f1ed", - "c485e443") + pat <- paste0( + "b2b7441d", + "aeeb010b", + "1df26f1f6", + "0a7f1ed", + "c485e443" + ) if (!quiet) { message("Using bundled GitHub PAT. Please add your own PAT to the env var `GITHUB_PAT`") } diff --git a/R/infrastructure-git.R b/R/infrastructure-git.R index 7ca4e442b..ee1d96b12 100644 --- a/R/infrastructure-git.R +++ b/R/infrastructure-git.R @@ -43,8 +43,10 @@ use_github <- function(auth_token = github_pat(), private = FALSE, pkg = ".", protocol = c("ssh", "https"), credentials = NULL, ...) { .Deprecated("usethis::use_github()", package = "devtools") warn_unless_current_dir(pkg) - usethis::use_github(auth_token = auth_token, private = private, host = host, - protocol = protocol, credentials = credentials, ...) + usethis::use_github( + auth_token = auth_token, private = private, host = host, + protocol = protocol, credentials = credentials, ... + ) } #' @rdname devtools-deprecated diff --git a/R/infrastructure.R b/R/infrastructure.R index ce71be832..08aa582e6 100644 --- a/R/infrastructure.R +++ b/R/infrastructure.R @@ -87,12 +87,12 @@ use_data <- usethis::use_data # `use_data` uses non-tidy NSE, so we cannot use it inside a function # hygienically. We could fix this with tidyevalation / rlang, but it seems # overkill just to get a deprecation message. -#function(..., pkg = ".", internal = FALSE, overwrite = FALSE, - #compress = "bzip2") { - #.Deprecated("usethis::use_data()", package = "devtools") - #usethis::use_data(..., internal = internal, overwrite = overwrite, - #compress = compress) -#} +# function(..., pkg = ".", internal = FALSE, overwrite = FALSE, +# compress = "bzip2") { +# .Deprecated("usethis::use_data()", package = "devtools") +# usethis::use_data(..., internal = internal, overwrite = overwrite, +# compress = compress) +# } #' @rdname devtools-deprecated #' @export @@ -169,7 +169,7 @@ use_cran_badge <- function(pkg = ".") { #' @rdname devtools-deprecated #' @export use_mit_license <- function(pkg = ".", - copyright_holder = getOption("devtools.name", "")) { + copyright_holder = getOption("devtools.name", "")) { .Deprecated("usethis::use_mit_license()", package = "devtools") warn_unless_current_dir(pkg) usethis::use_mit_license(copyright_holder = copyright_holder) diff --git a/R/install-bioc.r b/R/install-bioc.r index 459258f7e..984009f67 100644 --- a/R/install-bioc.r +++ b/R/install-bioc.r @@ -31,7 +31,7 @@ #' # Use `update_packages()` to upgrade the version of a package installed by #' any of the `install_*()` functions. #' update_packages("SummarizedExperiment") -#'} +#' } install_bioc <- function(repo, mirror = getOption("BioC_git", "https://git.bioconductor.org/packages"), ..., quiet = FALSE) { remotes <- lapply(repo, bioc_remote, mirror = mirror) @@ -49,8 +49,9 @@ parse_bioc_repo <- function(path) { param_names <- c("username", "password", "release", "repo", "commit", "invalid") replace <- stats::setNames(sprintf("\\%d", seq_along(param_names)), param_names) params <- lapply(replace, function(r) gsub(bioc_rx, r, path, perl = TRUE)) - if (params$invalid != "") + if (params$invalid != "") { stop(sprintf("Invalid bioc repo: %s", path)) + } params <- params[sapply(params, nchar) > 0] @@ -71,13 +72,13 @@ bioc_remote <- function(repo, mirror = getOption("BioC_git", "https://git.biocon } remote("bioc", - mirror = mirror, - repo = meta$repo, - url = paste0(mirror, "/", meta$repo), - release = meta$release %||% "release", - commit = meta$commit, - branch = branch, - credentials = meta$credentials + mirror = mirror, + repo = meta$repo, + url = paste0(mirror, "/", meta$repo), + release = meta$release %||% "release", + commit = meta$commit, + branch = branch, + credentials = meta$credentials ) } @@ -88,7 +89,7 @@ remote_download.bioc_remote <- function(x, quiet = FALSE) { } bundle <- tempfile() - git2r::clone(x$url, bundle, credentials=x$credentials, progress = FALSE) + git2r::clone(x$url, bundle, credentials = x$credentials, progress = FALSE) if (!is.null(x$branch)) { r <- git2r::repository(bundle) @@ -125,12 +126,12 @@ remote_sha.bioc_remote <- function(remote, ...) { # If the remote ref is the same as the sha it is a pinned commit so just # return that. if (!is.null(remote$ref) && - grepl(paste0("^", remote$ref), remote$sha)) { + grepl(paste0("^", remote$ref), remote$sha)) { return(remote$sha) } tryCatch({ - res <- git2r::remote_ls(remote$url, credentials=remote$credentials, ...) + res <- git2r::remote_ls(remote$url, credentials = remote$credentials, ...) found <- grep(pattern = paste0("/", remote$branch), x = names(res)) @@ -155,7 +156,7 @@ bioconductor_branch <- function(release, commit) { switch( tolower(release), devel = "master", - paste0("RELEASE_", gsub("\\.", "_", release)) + paste0("RELEASE_", gsub("\\.", "_", release)) ) } } @@ -164,8 +165,10 @@ bioconductor_release <- memoise::memoise(function() { tmp <- tempfile() download.file("http://bioconductor.org/config.yaml", tmp, quiet = TRUE) - gsub("release_version:[[:space:]]+\"([[:digit:].]+)\"", "\\1", - grep("release_version:", readLines(tmp), value = TRUE)) + gsub( + "release_version:[[:space:]]+\"([[:digit:].]+)\"", "\\1", + grep("release_version:", readLines(tmp), value = TRUE) + ) }) format.bioc_remote <- function(x, ...) { diff --git a/R/install-bitbucket.r b/R/install-bitbucket.r index 35fc572ef..2b665325e 100644 --- a/R/install-bitbucket.r +++ b/R/install-bitbucket.r @@ -28,23 +28,25 @@ install_bitbucket <- function(repo, username, ref = "master", subdir = NULL, quiet = FALSE, auth_user = NULL, password = NULL, ...) { - - remotes <- lapply(repo, bitbucket_remote, username = username, ref = ref, - subdir = subdir, auth_user = auth_user, password = password) + remotes <- lapply(repo, bitbucket_remote, + username = username, ref = ref, + subdir = subdir, auth_user = auth_user, password = password + ) install_remotes(remotes, ..., quiet = quiet) } bitbucket_remote <- function(repo, username = NULL, ref = NULL, subdir = NULL, - auth_user = NULL, password = NULL, sha = NULL) { - + auth_user = NULL, password = NULL, sha = NULL) { meta <- parse_git_repo(repo) meta$ref <- meta$ref %||% ref %||% "master" if (is.null(meta$username)) { meta$username <- username %||% stop("Unknown username.") warning("Username parameter is deprecated. Please use ", - username, "/", repo, call. = FALSE) + username, "/", repo, + call. = FALSE + ) } remote("bitbucket", @@ -66,13 +68,16 @@ remote_download.bitbucket_remote <- function(x, quiet = FALSE) { dest <- tempfile(fileext = paste0(".zip")) src <- paste("https://bitbucket.org/", x$username, "/", tolower(x$repo), "/get/", - x$ref, ".zip", sep = "") + x$ref, ".zip", + sep = "" + ) if (!is.null(x$password)) { auth <- httr::authenticate( user = x$auth_user %||% x$username, password = x$password, - type = "basic") + type = "basic" + ) } else { auth <- NULL } @@ -106,7 +111,7 @@ remote_package_name.bitbucket_remote <- function(remote, ...) { } #' @export -remote_sha.bitbucket_remote <-function(remote, ...) { +remote_sha.bitbucket_remote <- function(remote, ...) { remote_sha.github_remote(remote, url = "https://bitbucket.org", ...) } diff --git a/R/install-cran.r b/R/install-cran.r index 3bd166007..4467a2b3f 100644 --- a/R/install-cran.r +++ b/R/install-cran.r @@ -13,18 +13,17 @@ #' install_cran(c("httpuv", "shiny")) #' } install_cran <- function(pkgs, repos = getOption("repos"), type = getOption("pkgType"), ..., quiet = FALSE) { - remotes <- lapply(pkgs, cran_remote, repos = repos, type = type) install_remotes(remotes, quiet = quiet, ...) } cran_remote <- function(pkg, repos, type) { - remote("cran", name = pkg, repos = repos, - pkg_type = type) + pkg_type = type + ) } diff --git a/R/install-git.r b/R/install-git.r index 28a639e8d..08b556c52 100644 --- a/R/install-git.r +++ b/R/install-git.r @@ -24,16 +24,17 @@ #' # Use `update_packages()` to upgrade the version of a package installed by #' any of the `install_*()` functions. #' update_packages("stringr") -#'} -install_git <- function(url, subdir = NULL, branch = NULL, credentials = NULL, quiet=FALSE, ...) { - - remotes <- lapply(url, git_remote, subdir = subdir, - branch = branch, credentials=credentials) +#' } +install_git <- function(url, subdir = NULL, branch = NULL, credentials = NULL, quiet = FALSE, ...) { + remotes <- lapply(url, git_remote, + subdir = subdir, + branch = branch, credentials = credentials + ) install_remotes(remotes, quiet = quiet, ...) } -git_remote <- function(url, subdir = NULL, branch = NULL, credentials=NULL) { +git_remote <- function(url, subdir = NULL, branch = NULL, credentials = NULL) { remote("git", url = url, subdir = subdir, @@ -49,7 +50,7 @@ remote_download.git_remote <- function(x, quiet = FALSE) { } bundle <- tempfile() - git2r::clone(x$url, bundle, credentials=x$credentials, progress = FALSE) + git2r::clone(x$url, bundle, credentials = x$credentials, progress = FALSE) if (!is.null(x$branch)) { r <- git2r::repository(bundle) @@ -79,19 +80,23 @@ remote_metadata.git_remote <- function(x, bundle = NULL, source = NULL) { #' @export remote_package_name.git_remote <- function(remote, ...) { - tmp <- tempfile() on.exit(unlink(tmp)) description_path <- paste0(collapse = "/", c(remote$subdir, "DESCRIPTION")) # Try using git archive --remote to retrieve the DESCRIPTION, if the protocol # or server doesn't support that return NULL - res <- try(silent = TRUE, + res <- try( + silent = TRUE, system_check(git_path(), - args = c("archive", "-o", tmp, "--remote", remote$url, + args = c( + "archive", "-o", tmp, "--remote", remote$url, if (is.null(remote$branch)) "HEAD" else remote$branch, - description_path), - quiet = TRUE)) + description_path + ), + quiet = TRUE + ) + ) if (inherits(res, "try-error")) { return(NA_character_) @@ -106,7 +111,7 @@ remote_package_name.git_remote <- function(remote, ...) { #' @export remote_sha.git_remote <- function(remote, ...) { tryCatch({ - res <- git2r::remote_ls(remote$url, credentials=remote$credentials, ...) + res <- git2r::remote_ls(remote$url, credentials = remote$credentials, ...) branch <- remote$branch %||% "master" diff --git a/R/install-github.r b/R/install-github.r index 67c067373..a6df69fb0 100644 --- a/R/install-github.r +++ b/R/install-github.r @@ -60,17 +60,17 @@ install_github <- function(repo, username = NULL, auth_token = github_pat(), host = "https://api.github.com", quiet = FALSE, ...) { - - remotes <- lapply(repo, github_remote, username = username, ref = ref, - subdir = subdir, auth_token = auth_token, host = host) + remotes <- lapply(repo, github_remote, + username = username, ref = ref, + subdir = subdir, auth_token = auth_token, host = host + ) install_remotes(remotes, quiet = quiet, ...) } github_remote <- function(repo, username = NULL, ref = NULL, subdir = NULL, - auth_token = github_pat(), sha = NULL, - host = "https://api.github.com") { - + auth_token = github_pat(), sha = NULL, + host = "https://api.github.com") { meta <- parse_git_repo(repo) meta <- github_resolve_ref(meta$ref %||% ref, meta, auth_token = auth_token, host = host) @@ -78,7 +78,9 @@ github_remote <- function(repo, username = NULL, ref = NULL, subdir = NULL, meta$username <- username %||% getOption("github.user") %||% stop("Unknown username.") warning("Username parameter is deprecated. Please use ", - username, "/", repo, call. = FALSE) + username, "/", repo, + call. = FALSE + ) } remote("github", @@ -104,8 +106,10 @@ remote_download.github_remote <- function(x, quiet = FALSE) { src <- paste0(src_root, "/tarball/", x$ref) if (!quiet) { - message("Downloading GitHub repo ", x$username, "/", x$repo, "@", x$ref, - "\nfrom URL ", src) + message( + "Downloading GitHub repo ", x$username, "/", x$repo, "@", x$ref, + "\nfrom URL ", src + ) } if (!is.null(x$auth_token)) { @@ -118,9 +122,11 @@ remote_download.github_remote <- function(x, quiet = FALSE) { auth <- NULL } - if (github_has_remotes(x, auth)) + if (github_has_remotes(x, auth)) { warning("GitHub repo contains submodules, may not function as expected!", - call. = FALSE) + call. = FALSE + ) + } download_github(dest, src, auth) } @@ -208,8 +214,9 @@ github_resolve_ref.github_release <- function(x, params, ..., auth_token, host) # GET /repos/:user/:repo/releases path <- paste("repos", params$username, params$repo, "releases", sep = "/") response <- github_GET(path, pat = auth_token, host = host) - if (length(response) == 0L) + if (length(response) == 0L) { stop("No releases found for repo ", params$username, "/", params$repo, ".") + } params$ref <- response[[1L]]$tag_name params @@ -225,14 +232,17 @@ parse_git_repo <- function(path) { pull_rx <- "(?:#([0-9]+))" release_rx <- "(?:@([*]release))" ref_or_pull_or_release_rx <- sprintf("(?:%s|%s|%s)?", ref_rx, pull_rx, release_rx) - github_rx <- sprintf("^(?:%s%s%s%s|(.*))$", - username_rx, repo_rx, subdir_rx, ref_or_pull_or_release_rx) + github_rx <- sprintf( + "^(?:%s%s%s%s|(.*))$", + username_rx, repo_rx, subdir_rx, ref_or_pull_or_release_rx + ) param_names <- c("username", "repo", "subdir", "ref", "pull", "release", "invalid") replace <- stats::setNames(sprintf("\\%d", seq_along(param_names)), param_names) params <- lapply(replace, function(r) gsub(github_rx, r, path, perl = TRUE)) - if (params$invalid != "") + if (params$invalid != "") { stop(sprintf("Invalid git repo: %s", path)) + } params <- params[sapply(params, nchar) > 0] if (!is.null(params$pull)) { @@ -250,14 +260,14 @@ parse_git_repo <- function(path) { #' @export remote_package_name.github_remote <- function(remote, url = "https://raw.githubusercontent.com", ...) { - tmp <- tempfile() path <- paste(c( - remote$username, - remote$repo, - remote$ref, - remote$subdir, - "DESCRIPTION"), collapse = "/") + remote$username, + remote$repo, + remote$ref, + remote$subdir, + "DESCRIPTION" + ), collapse = "/") if (!is.null(remote$auth_token)) { auth <- httr::authenticate( @@ -282,14 +292,17 @@ remote_package_name.github_remote <- function(remote, url = "https://raw.githubu remote_sha.github_remote <- function(remote, url = "https://github.com", ...) { tryCatch({ # honour credentials if any - cred <- if(!is.null(remote$auth_token)){ + cred <- if (!is.null(remote$auth_token)) { git2r::cred_user_pass( username = github_user(pat = remote$auth_token, host = remote$host), - password = remote$auth_token) + password = remote$auth_token + ) } res <- git2r::remote_ls( paste0(url, "/", remote$username, "/", remote$repo, ".git"), - ..., credentials = cred) + ..., + credentials = cred + ) found <- grep(pattern = paste0("\\b", remote$ref), x = names(res), perl = TRUE) @@ -311,7 +324,7 @@ download_github <- function(path, url, ...) { request <- httr::GET(url, ...) if (httr::status_code(request) >= 400) { - stop(github_error(request)) + stop(github_error(request)) } writeBin(httr::content(request, "raw"), path) diff --git a/R/install-gitlab.r b/R/install-gitlab.r index b236c274a..2e563004d 100644 --- a/R/install-gitlab.r +++ b/R/install-gitlab.r @@ -18,18 +18,15 @@ #' } install_gitlab <- function(repo, auth_token = gitlab_pat(), - host = "https://www.gitlab.com", quiet = FALSE, ...) -{ - + host = "https://www.gitlab.com", quiet = FALSE, ...) { remotes <- lapply(repo, gitlab_remote, auth_token = auth_token, host = host) install_remotes(remotes, quiet = quiet, ...) } gitlab_remote <- function(repo, - auth_token = gitlab_pat(), sha = NULL, - host = "https://www.gitlab.com") { - + auth_token = gitlab_pat(), sha = NULL, + host = "https://www.gitlab.com") { meta <- parse_git_repo(repo) meta$ref <- meta$ref %||% "master" @@ -56,8 +53,10 @@ remote_download.gitlab_remote <- function(x, quiet = FALSE) { src <- paste0(src_root, "/repository/archive.zip?ref=", utils::URLencode(x$ref, reserved = TRUE)) if (!quiet) { - message("Downloading GitLab repo ", x$username, "/", x$repo, "@", x$ref, - "\nfrom URL ", src) + message( + "Downloading GitLab repo ", x$username, "/", x$repo, "@", x$ref, + "\nfrom URL ", src + ) } if (!is.null(x$auth_token)) { @@ -97,15 +96,15 @@ remote_metadata.gitlab_remote <- function(x, bundle = NULL, source = NULL) { #' @export remote_package_name.gitlab_remote <- function(remote, url = "https://gitlab.com/", ...) { - tmp <- tempfile() path <- paste(c( - remote$username, - remote$repo, - "raw", - remote$ref, - remote$subdir, - "DESCRIPTION"), collapse = "/") + remote$username, + remote$repo, + "raw", + remote$ref, + remote$subdir, + "DESCRIPTION" + ), collapse = "/") if (!is.null(remote$auth_token)) { auth <- httr::authenticate( @@ -119,8 +118,10 @@ remote_package_name.gitlab_remote <- function(remote, url = "https://gitlab.com/ # We do not follow redirects because GitLab does a 302 redirect to the sign-in # page if the repository does not exist. - req <- httr::GET(url, path = path, httr::write_disk(path = tmp), - auth, httr::config(followlocation = FALSE)) + req <- httr::GET(url, + path = path, httr::write_disk(path = tmp), + auth, httr::config(followlocation = FALSE) + ) if (httr::status_code(req) >= 300) { return(NA_character_) @@ -134,7 +135,8 @@ remote_sha.gitlab_remote <- function(remote, url = "https://gitlab.com", ...) { tryCatch({ res <- git2r::remote_ls( paste0(url, "/", remote$username, "/", remote$repo, ".git"), - ...) + ... + ) found <- grep(pattern = paste0("\\b", remote$ref), x = names(res), perl = TRUE) diff --git a/R/install-remote.R b/R/install-remote.R index a6af2994f..1c31d5160 100644 --- a/R/install-remote.R +++ b/R/install-remote.R @@ -22,12 +22,12 @@ install_remote <- function(remote, ..., force = FALSE, quiet = FALSE, if (!isTRUE(force) && !different_sha(remote_sha = remote_sha, local_sha = local_sha)) { - if (!quiet) { message( "Skipping install of '", package_name, "' from a ", sub("_remote", "", class(remote)[1L]), " remote,", " the SHA1 (", substr(remote_sha, 1L, 8L), ") has not changed since last install.\n", - " Use `force = TRUE` to force installation") + " Use `force = TRUE` to force installation" + ) } return(invisible(FALSE)) } @@ -42,9 +42,11 @@ install_remote <- function(remote, ..., force = FALSE, quiet = FALSE, if (is_windows && inherits(remote, "cran_remote")) { install_packages( - package_name, repos = remote$repos, type = remote$pkg_type, + package_name, + repos = remote$repos, type = remote$pkg_type, dependencies = dependencies, ..., quiet = quiet, out_dir = out_dir, - skip_if_log_exists = skip_if_log_exists) + skip_if_log_exists = skip_if_log_exists + ) return(invisible(TRUE)) } @@ -52,8 +54,10 @@ install_remote <- function(remote, ..., force = FALSE, quiet = FALSE, on.exit(unlink(bundle), add = TRUE) if (inherits(remote, "url_remote") && remote$pkg_type == "binary") { - install_packages(bundle, repos = NULL, dependencies = dependencies, ..., - quiet = quiet, out_dir = out_dir, skip_if_log_exists = skip_if_log_exists) + install_packages(bundle, + repos = NULL, dependencies = dependencies, ..., + quiet = quiet, out_dir = out_dir, skip_if_log_exists = skip_if_log_exists + ) return(invisible(TRUE)) } @@ -62,9 +66,11 @@ install_remote <- function(remote, ..., force = FALSE, quiet = FALSE, metadata <- remote_metadata(remote, bundle, source) - install(source, ..., quiet = quiet, metadata = metadata, - out_dir = out_dir, skip_if_log_exists = skip_if_log_exists, - repos = repos, type = type, dependencies = dependencies) + install(source, ..., + quiet = quiet, metadata = metadata, + out_dir = out_dir, skip_if_log_exists = skip_if_log_exists, + repos = repos, type = type, dependencies = dependencies + ) } install_remotes <- function(remotes, ...) { @@ -99,7 +105,6 @@ add_metadata <- function(pkg_path, meta) { if (!file.exists(source_desc) && !file.exists(binary_desc)) { stop("No DESCRIPTION found!", call. = FALSE) } - } # Modify the MD5 file - remove the line for DESCRIPTION @@ -147,26 +152,27 @@ remote_package_name <- function(remote, ...) UseMethod("remote_package_name") remote_sha <- function(remote, ...) UseMethod("remote_sha") package2remote <- function(name, repos = getOption("repos"), type = getOption("pkgType")) { - x <- tryCatch(packageDescription(name, lib.loc = .libPaths()), error = function(e) NA, warning = function(e) NA) # will be NA if not installed if (identical(x, NA)) { return(remote("cran", - name = name, - repos = repos, - pkg_type = type, - sha = NA_character_)) + name = name, + repos = repos, + pkg_type = type, + sha = NA_character_ + )) } if (is.null(x$RemoteType)) { # Packages installed with install.packages() or locally without devtools return(remote("cran", - name = x$Package, - repos = repos, - pkg_type = type, - sha = x$Version)) + name = x$Package, + repos = repos, + pkg_type = type, + sha = x$Version + )) } switch(x$RemoteType, @@ -176,32 +182,37 @@ package2remote <- function(name, repos = getOption("repos"), type = getOption("p subdir = x$RemoteSubdir, username = x$RemoteUsername, ref = x$RemoteRef, - sha = x$RemoteSha), + sha = x$RemoteSha + ), gitlab = remote("gitlab", host = x$RemoteHost, repo = x$RemoteRepo, subdir = x$RemoteSubdir, username = x$RemoteUsername, ref = x$RemoteRef, - sha = x$RemoteSha), + sha = x$RemoteSha + ), git = remote("git", url = x$RemoteUrl, ref = x$RemoteRef, sha = x$RemoteSha, - subdir = x$RemoteSubdir), + subdir = x$RemoteSubdir + ), bitbucket = remote("bitbucket", host = x$RemoteHost, repo = x$RemoteRepo, username = x$RemoteUsername, ref = x$RemoteRef, sha = x$RemoteSha, - subdir = x$RemoteSubdir), + subdir = x$RemoteSubdir + ), svn = remote("svn", url = x$RemoteUrl, svn_subdir = x$RemoteSvnSubdir, branch = x$RemoteBranch, sha = x$RemoteRevision, - args = x$RemoteArgs), + args = x$RemoteArgs + ), local = remote("local", path = x$RemoteUrl, branch = x$RemoteBranch, @@ -215,12 +226,14 @@ package2remote <- function(name, repos = getOption("repos"), type = getOption("p sha }, username = x$RemoteUsername, - repo = x$RemoteRepo), + repo = x$RemoteRepo + ), url = remote("url", url = x$RemoteUrl, subdir = x$RemoteSubdir, config = x$RemoteConfig, - pkg_type = x$RemotePkgType), + pkg_type = x$RemotePkgType + ), bioc = remote("bioc", repo = x$RemoteRepo, mirror = x$RemoteMirror, @@ -228,14 +241,17 @@ package2remote <- function(name, repos = getOption("repos"), type = getOption("p username = x$RemoteUsername, password = x$RemotePassword, revision = x$RemoteRevision, - sha = x$RemoteSha), + sha = x$RemoteSha + ), # packages installed with install_cran cran = remote("cran", name = x$Package, repos = eval(parse(text = x$RemoteRepos)), pkg_type = x$RemotePkgType, - sha = x$RemoteSha)) + sha = x$RemoteSha + ) + ) } #' @export diff --git a/R/install-svn.r b/R/install-svn.r index 03ee1b9e7..8cc4e0888 100644 --- a/R/install-svn.r +++ b/R/install-svn.r @@ -25,18 +25,19 @@ #' # Use `update_packages()` to upgrade the version of a package installed by #' any of the `install_*()` functions. #' update_packages("stringr") -#'} +#' } install_svn <- function(url, subdir = NULL, args = character(0), - ..., revision = NULL, quiet = FALSE) { - - remotes <- lapply(url, svn_remote, svn_subdir = subdir, - revision = revision, args = args) + ..., revision = NULL, quiet = FALSE) { + remotes <- lapply(url, svn_remote, + svn_subdir = subdir, + revision = revision, args = args + ) install_remotes(remotes, ..., quiet = quiet) } svn_remote <- function(url, svn_subdir = NULL, revision = NULL, - args = character(0)) { + args = character(0)) { remote("svn", url = url, svn_subdir = svn_subdir, @@ -83,7 +84,6 @@ remote_download.svn_remote <- function(x, quiet = FALSE) { #' @export remote_metadata.svn_remote <- function(x, bundle = NULL, source = NULL) { - if (!is.null(bundle)) { withr::with_dir(bundle, { revision <- svn_revision() diff --git a/R/install-url.r b/R/install-url.r index 353b21809..4b5fa65f2 100644 --- a/R/install-url.r +++ b/R/install-url.r @@ -28,11 +28,10 @@ install_url <- function(url, subdir = NULL, config = list(), ..., quiet = FALSE) } url_remote <- function(url, subdir = NULL, config = list()) { - if (file_ext(url) == "zip" || file_ext(url) == "tgz") { - pkg_type = "binary" + pkg_type <- "binary" } else { - pkg_type = "source" + pkg_type <- "source" } remote("url", diff --git a/R/install-version.r b/R/install-version.r index d42b865eb..17e16b03c 100644 --- a/R/install-version.r +++ b/R/install-version.r @@ -16,13 +16,12 @@ #' @inheritParams install_url #' @author Jeremy Stephens install_version <- function(package, version = NULL, - repos = getOption("repos"), type = getOption("pkgType"), ..., quiet = FALSE) { - + repos = getOption("repos"), type = getOption("pkgType"), ..., quiet = FALSE) { contriburl <- contrib.url(repos, type) available <- available.packages(contriburl) if (package %in% row.names(available)) { - current.version <- available[package, 'Version'] + current.version <- available[package, "Version"] if (is.null(version) || version == current.version) { return(install.packages(package, repos = repos, type = type, ...)) } @@ -35,10 +34,13 @@ install_version <- function(package, version = NULL, package.path <- info$path[NROW(info)] } else { package.path <- paste(package, "/", package, "_", version, ".tar.gz", - sep = "") + sep = "" + ) if (!(package.path %in% info$path)) { - stop(sprintf("version '%s' is invalid for package '%s'", version, - package)) + stop(sprintf( + "version '%s' is invalid for package '%s'", version, + package + )) } } @@ -52,14 +54,20 @@ read_archive <- function(repo) { on.exit(close(con)) readRDS(con) }, - warning = function(e) { list() }, - error = function(e) { list() }) + warning = function(e) { + list() + }, + error = function(e) { + list() + } + ) } package_find_repo <- function(package, repos) { archive_info <- function(repo) { - if (length(repos) > 1) + if (length(repos) > 1) { message("Trying ", repo) + } archive <- read_archive(repo) @@ -71,8 +79,10 @@ package_find_repo <- function(package, repos) { } } - res <- do.call(rbind.data.frame, - c(lapply(repos, archive_info), list(make.row.names = FALSE))) + res <- do.call( + rbind.data.frame, + c(lapply(repos, archive_info), list(make.row.names = FALSE)) + ) if (NROW(res) == 0) { stop(sprintf("couldn't find package '%s'", package)) diff --git a/R/install.r b/R/install.r index 9276f5992..012d2160e 100644 --- a/R/install.r +++ b/R/install.r @@ -62,120 +62,123 @@ #' @export install <- function(pkg = ".", reload = TRUE, quick = FALSE, local = TRUE, - args = getOption("devtools.install.args"), quiet = FALSE, - dependencies = NA, upgrade_dependencies = TRUE, - build_vignettes = FALSE, - keep_source = getOption("keep.source.pkgs"), - threads = getOption("Ncpus", 1), - force_deps = FALSE, - metadata = remote_metadata(as.package(pkg)), - out_dir = NULL, - skip_if_log_exists = FALSE, - ...) { - - pkg <- as.package(pkg) - - # Forcing all of the promises for the current namespace now will avoid lazy-load - # errors when the new package is installed overtop the old one. - # https://stat.ethz.ch/pipermail/r-devel/2015-December/072150.html - if (is_loaded(pkg)) { - eapply(pkgload::ns_env(pkg$package), force, all.names = TRUE) - } + args = getOption("devtools.install.args"), quiet = FALSE, + dependencies = NA, upgrade_dependencies = TRUE, + build_vignettes = FALSE, + keep_source = getOption("keep.source.pkgs"), + threads = getOption("Ncpus", 1), + force_deps = FALSE, + metadata = remote_metadata(as.package(pkg)), + out_dir = NULL, + skip_if_log_exists = FALSE, + ...) { + pkg <- as.package(pkg) + + # Forcing all of the promises for the current namespace now will avoid lazy-load + # errors when the new package is installed overtop the old one. + # https://stat.ethz.ch/pipermail/r-devel/2015-December/072150.html + if (is_loaded(pkg)) { + eapply(pkgload::ns_env(pkg$package), force, all.names = TRUE) + } - root_install <- is.null(installing$packages) - if (root_install) { - on.exit(installing$packages <- NULL, add = TRUE) - } + root_install <- is.null(installing$packages) + if (root_install) { + on.exit(installing$packages <- NULL, add = TRUE) + } + + if (pkg$package %in% installing$packages) { + if (!quiet) { + message("Skipping ", pkg$package, ", it is already being installed.") + } + return(invisible(FALSE)) + } + + if (!is.null(out_dir)) { + out_file <- file.path(out_dir, paste0(pkg$package, ".out")) + if (skip_if_log_exists && file.exists(out_file)) { + message("Skipping ", pkg$package, ", installation failed before, see log in ", out_file) + return(invisible(FALSE)) + } + } else { + out_file <- NULL + } - if (pkg$package %in% installing$packages) { + installing$packages <- c(installing$packages, pkg$package) if (!quiet) { - message("Skipping ", pkg$package, ", it is already being installed.") + message("Installing ", pkg$package) } - return(invisible(FALSE)) - } - if (!is.null(out_dir)) { - out_file <- file.path(out_dir, paste0(pkg$package, ".out")) - if (skip_if_log_exists && file.exists(out_file)) { - message("Skipping ", pkg$package, ", installation failed before, see log in ", out_file) - return(invisible(FALSE)) + # If building vignettes, make sure we have all suggested packages too. + if (build_vignettes && missing(dependencies)) { + dependencies <- standardise_dep(TRUE) + } else { + dependencies <- standardise_dep(dependencies) } - } else { - out_file <- NULL - } - installing$packages <- c(installing$packages, pkg$package) - if (!quiet) { - message("Installing ", pkg$package) - } + initial_deps <- dependencies[dependencies != "Suggests"] + final_deps <- dependencies[dependencies == "Suggests"] - # If building vignettes, make sure we have all suggested packages too. - if (build_vignettes && missing(dependencies)) { - dependencies <- standardise_dep(TRUE) - } else { - dependencies <- standardise_dep(dependencies) - } + # cache the Remote: dependencies here so we don't have to query them each + # time we call install_deps + installing$remote_deps <- remote_deps(pkg) + on.exit(installing$remote_deps <- NULL, add = TRUE) - initial_deps <- dependencies[dependencies != "Suggests"] - final_deps <- dependencies[dependencies == "Suggests"] - - # cache the Remote: dependencies here so we don't have to query them each - # time we call install_deps - installing$remote_deps <- remote_deps(pkg) - on.exit(installing$remote_deps <- NULL, add = TRUE) - - install_deps(pkg, dependencies = initial_deps, upgrade = upgrade_dependencies, - threads = threads, force_deps = force_deps, quiet = quiet, ..., - out_dir = out_dir, skip_if_log_exists = skip_if_log_exists) - - # Build the package. Only build locally if it doesn't have vignettes - has_vignettes <- length(tools::pkgVignettes(dir = pkg$path)$docs > 0) - if (local && !(has_vignettes && build_vignettes)) { - built_path <- pkg$path - } else { - built_path <- pkgbuild::build( - pkg$path, - tempdir(), - vignettes = build_vignettes, - quiet = quiet + install_deps(pkg, + dependencies = initial_deps, upgrade = upgrade_dependencies, + threads = threads, force_deps = force_deps, quiet = quiet, ..., + out_dir = out_dir, skip_if_log_exists = skip_if_log_exists ) - on.exit(unlink(built_path), add = TRUE) - } - opts <- c( - paste("--library=", .libPaths()[1], sep = ""), - if (keep_source) "--with-keep.source", - "--install-tests" - ) - if (quick) { - opts <- c(opts, "--no-docs", "--no-multiarch", "--no-demo") - } - opts <- c(opts, args) + # Build the package. Only build locally if it doesn't have vignettes + has_vignettes <- length(tools::pkgVignettes(dir = pkg$path)$docs > 0) + if (local && !(has_vignettes && build_vignettes)) { + built_path <- pkg$path + } else { + built_path <- pkgbuild::build( + pkg$path, + tempdir(), + vignettes = build_vignettes, + quiet = quiet + ) + on.exit(unlink(built_path), add = TRUE) + } - built_path <- normalizePath(built_path, winslash = "/") + opts <- c( + paste("--library=", .libPaths()[1], sep = ""), + if (keep_source) "--with-keep.source", + "--install-tests" + ) + if (quick) { + opts <- c(opts, "--no-docs", "--no-multiarch", "--no-demo") + } + opts <- c(opts, args) - pkgbuild::rcmd_build_tools( - "INSTALL", - c(built_path, opts), - echo = !quiet, - show = !quiet, - fail_on_status = TRUE, - required = FALSE - ) + built_path <- normalizePath(built_path, winslash = "/") - install_deps(pkg, dependencies = final_deps, upgrade = upgrade_dependencies, - threads = threads, force_deps = force_deps, quiet = quiet, ..., - out_dir = out_dir, skip_if_log_exists = skip_if_log_exists) + pkgbuild::rcmd_build_tools( + "INSTALL", + c(built_path, opts), + echo = !quiet, + show = !quiet, + fail_on_status = TRUE, + required = FALSE + ) - if (length(metadata) > 0) { - add_metadata(pkgload::inst(pkg$package), metadata) - } + install_deps(pkg, + dependencies = final_deps, upgrade = upgrade_dependencies, + threads = threads, force_deps = force_deps, quiet = quiet, ..., + out_dir = out_dir, skip_if_log_exists = skip_if_log_exists + ) - if (reload) { - reload(pkg, quiet = quiet) + if (length(metadata) > 0) { + add_metadata(pkgload::inst(pkg$package), metadata) + } + + if (reload) { + reload(pkg, quiet = quiet) + } + invisible(TRUE) } - invisible(TRUE) -} # A environment to hold which packages are being installed so packages with # circular dependencies can be skipped the second time. @@ -203,12 +206,15 @@ install_deps <- function(pkg = ".", dependencies = NA, upgrade = TRUE, quiet = FALSE, force_deps = FALSE) { - - pkg <- dev_package_deps(pkg, repos = repos, dependencies = dependencies, - type = type) + pkg <- dev_package_deps(pkg, + repos = repos, dependencies = dependencies, + type = type + ) if (!quiet) print(pkg) - update(pkg, ..., repos = repos, type = type, threads = threads, quiet = - quiet, upgrade = upgrade, force = force_deps) + update(pkg, ..., + repos = repos, type = type, threads = threads, quiet = + quiet, upgrade = upgrade, force = force_deps + ) invisible() } @@ -216,6 +222,8 @@ install_deps <- function(pkg = ".", dependencies = NA, #' @export install_dev_deps <- function(pkg = ".", ...) { update_packages("roxygen2") - install_deps(pkg, ..., dependencies = TRUE, upgrade = FALSE, - bioc_packages = TRUE) + install_deps(pkg, ..., + dependencies = TRUE, upgrade = FALSE, + bioc_packages = TRUE + ) } diff --git a/R/package.r b/R/package.r index 87be32b3d..9ad35999a 100644 --- a/R/package.r +++ b/R/package.r @@ -57,7 +57,7 @@ package_file <- function(..., path = ".") { } has_description <- function(path) { - file.exists(file.path(path, 'DESCRIPTION')) + file.exists(file.path(path, "DESCRIPTION")) } is_root <- function(path) { diff --git a/R/pkgbuild.R b/R/pkgbuild.R index a04e41c7a..17e10b48d 100644 --- a/R/pkgbuild.R +++ b/R/pkgbuild.R @@ -6,8 +6,10 @@ build <- function(path = ".", dest_path = NULL, binary = FALSE, vignettes = TRUE if (rstudioapi::hasFun("documentSaveAll")) { rstudioapi::documentSaveAll() } - pkgbuild::build(path = path, dest_path = dest_path, binary = binary, - vignettes = vignettes, manual = manual, args = args, quiet = quiet, ...) + pkgbuild::build( + path = path, dest_path = dest_path, binary = binary, + vignettes = vignettes, manual = manual, args = args, quiet = quiet, ... + ) } #' @importFrom pkgbuild with_debug diff --git a/R/pkgload.R b/R/pkgload.R index a8b45039f..ebedff4bd 100644 --- a/R/pkgload.R +++ b/R/pkgload.R @@ -7,8 +7,10 @@ load_all <- function(path = ".", reset = TRUE, recompile = FALSE, rstudioapi::documentSaveAll() } - pkgload::load_all(path = path, reset = reset, recompile = recompile, - export_all = export_all, helpers = helpers, quiet = quiet, ...) + pkgload::load_all( + path = path, reset = reset, recompile = recompile, + export_all = export_all, helpers = helpers, quiet = quiet, ... + ) } #' @importFrom pkgload unload diff --git a/R/r-hub.R b/R/r-hub.R index beceff085..9a20829d2 100644 --- a/R/r-hub.R +++ b/R/r-hub.R @@ -34,7 +34,6 @@ check_rhub <- function(pkg = ".", email = NULL, interactive = TRUE, ...) { - check_suggested("rhub") pkg <- as.package(pkg) diff --git a/R/release.r b/R/release.r index b6caa4997..ad728e0d2 100644 --- a/R/release.r +++ b/R/release.r @@ -46,12 +46,14 @@ release <- function(pkg = ".", check = FALSE, args = NULL) { if (!dr_d) { print(dr_d) - if (yesno("Proceed anyway?")) + if (yesno("Proceed anyway?")) { return(invisible()) + } } - if (yesno("Have you checked for spelling errors (with `spell_check()`)?")) + if (yesno("Have you checked for spelling errors (with `spell_check()`)?")) { return(invisible()) + } if (check) { cat_rule( @@ -59,53 +61,65 @@ release <- function(pkg = ".", check = FALSE, args = NULL) { right = pkg$package, line = 2 ) - check(pkg, cran = TRUE, remote = TRUE, manual = TRUE, - build_args = args, run_dont_test = TRUE) + check(pkg, + cran = TRUE, remote = TRUE, manual = TRUE, + build_args = args, run_dont_test = TRUE + ) } - if (yesno("Have you run `R CMD check` locally?")) + if (yesno("Have you run `R CMD check` locally?")) { return(invisible()) + } release_checks(pkg) - if (yesno("Were devtool's checks successful?")) + if (yesno("Were devtool's checks successful?")) { return(invisible()) + } if (!new_pkg) { - show_cran_check <- TRUE - cran_details <- NULL - end_sentence <- " ?" - if (requireNamespace("foghorn", quietly = TRUE)) { - show_cran_check <- has_cran_results(pkg$package) - cran_details <- foghorn::cran_details(pkg = pkg$package) + show_cran_check <- TRUE + cran_details <- NULL + end_sentence <- " ?" + if (requireNamespace("foghorn", quietly = TRUE)) { + show_cran_check <- has_cran_results(pkg$package) + cran_details <- foghorn::cran_details(pkg = pkg$package) + } + if (show_cran_check) { + if (!is.null(cran_details)) { + end_sentence <- "\n shown above?" + cat_rule(paste0("Details of the CRAN check results for ", pkg$package)) + summary(cran_details) + cat_rule() } - if (show_cran_check) { - if (!is.null(cran_details)) { - end_sentence <- "\n shown above?" - cat_rule(paste0("Details of the CRAN check results for ", pkg$package)) - summary(cran_details) - cat_rule() - } - cran_url <- paste0(cran_mirror(), "/web/checks/check_results_", - pkg$package, ".html") - if (yesno("Have you fixed all existing problems at \n", cran_url, - end_sentence)) - return(invisible()) + cran_url <- paste0( + cran_mirror(), "/web/checks/check_results_", + pkg$package, ".html" + ) + if (yesno( + "Have you fixed all existing problems at \n", cran_url, + end_sentence + )) { + return(invisible()) } + } } - if (yesno("Have you checked on R-hub (with `check_rhub()`)?")) + if (yesno("Have you checked on R-hub (with `check_rhub()`)?")) { return(invisible()) + } - if (yesno("Have you checked on win-builder (with `check_win_devel()`)?")) + if (yesno("Have you checked on win-builder (with `check_win_devel()`)?")) { return(invisible()) + } deps <- if (new_pkg) 0 else length(revdep(pkg$package)) if (deps > 0) { msg <- paste0( - "Have you checked the ", deps , " reverse dependencies ", + "Have you checked the ", deps, " reverse dependencies ", "(with the revdepcheck package)?" ) - if (yesno(msg)) + if (yesno(msg)) { return(invisible()) + } } questions <- c( @@ -122,8 +136,9 @@ release <- function(pkg = ".", check = FALSE, args = NULL) { if (uses_git(pkg$path)) { git_checks(pkg) - if (yesno("Were Git checks successful?")) + if (yesno("Were Git checks successful?")) { return(invisible()) + } } submit_cran(pkg, args = args) @@ -156,16 +171,20 @@ release_email <- function(name, new_pkg) { "\n", if (new_pkg) { paste("I have uploaded a new package, ", name, ", to CRAN. ", - "I have read and agree to the CRAN policies.\n", sep = "") + "I have read and agree to the CRAN policies.\n", + sep = "" + ) } else { paste("I have just uploaded a new version of ", name, " to CRAN.\n", - sep = "") + sep = "" + ) }, "\n", "Thanks!\n", "\n", getOption("devtools.name"), "\n", - sep = "") + sep = "" + ) } yesno <- function(...) { @@ -190,26 +209,29 @@ email <- function(address, subject, body) { ) tryCatch({ - utils::browseURL(url, browser = email_browser())}, - error = function(e) { - message("Sending failed with error: ", e$message) - cat("To: ", address, "\n", sep = "") - cat("Subject: ", subject, "\n", sep = "") - cat("\n") - cat(body, "\n", sep = "") - } + utils::browseURL(url, browser = email_browser()) + }, + error = function(e) { + message("Sending failed with error: ", e$message) + cat("To: ", address, "\n", sep = "") + cat("Subject: ", subject, "\n", sep = "") + cat("\n") + cat(body, "\n", sep = "") + } ) invisible(TRUE) } email_browser <- function() { - if (!identical(.Platform$GUI, "RStudio")) - return (getOption("browser")) + if (!identical(.Platform$GUI, "RStudio")) { + return(getOption("browser")) + } # Use default browser, even if RStudio running - if (.Platform$OS.type == "windows") - return (NULL) + if (.Platform$OS.type == "windows") { + return(NULL) + } browser <- Sys.which(c("xdg-open", "open")) browser[nchar(browser) > 0][[1]] @@ -249,7 +271,8 @@ cran_comments <- function(pkg = ".") { warning("Can't find cran-comments.md.\n", "This file gives CRAN volunteers comments about the submission,\n", "Create it with use_cran_comments().\n", - call. = FALSE) + call. = FALSE + ) return(character()) } @@ -273,11 +296,13 @@ cran_submission_url <- "http://xmpalantir.wu.ac.at/cransubmit/index2.php" #' @export #' @keywords internal submit_cran <- function(pkg = ".", args = NULL) { - if (yesno("Is your email address ", maintainer(pkg)$email, "?")) + if (yesno("Is your email address ", maintainer(pkg)$email, "?")) { return(invisible()) + } - if (yesno("Ready to submit to CRAN?")) + if (yesno("Ready to submit to CRAN?")) { return(invisible()) + } pkg <- as.package(pkg) built_path <- build_cran(pkg, args = args) @@ -290,8 +315,10 @@ build_cran <- function(pkg, args) { message("Building") built_path <- pkgbuild::build(pkg$path, tempdir(), manual = TRUE, args = args) message("Submitting file: ", built_path) - message("File size: ", - format(as.object_size(file.info(built_path)$size), units = "auto")) + message( + "File size: ", + format(as.object_size(file.info(built_path)$size), units = "auto") + ) built_path } @@ -327,8 +354,10 @@ upload_cran <- function(pkg, built_path) { httr::stop_for_status(r) new_url <- httr::parse_url(r$url) if (new_url$query$submit == "1") { - message("Package submission successful.\n", - "Check your email for confirmation link.") + message( + "Package submission successful.\n", + "Check your email for confirmation link." + ) } else { stop("Package failed to upload.", call. = FALSE) } diff --git a/R/reload.r b/R/reload.r index eb7357cca..1c282005d 100644 --- a/R/reload.r +++ b/R/reload.r @@ -31,4 +31,3 @@ reload <- function(pkg = ".", quiet = FALSE) { require(pkg$package, character.only = TRUE, quietly = TRUE) } } - diff --git a/R/revdep-email.R b/R/revdep-email.R index d2f898398..4adcab706 100644 --- a/R/revdep-email.R +++ b/R/revdep-email.R @@ -51,11 +51,13 @@ revdep_email <- function(pkg = ".", date, } gh <- github_info(pkg$path) - data <- lapply(results, maintainer_data, pkg = pkg, version = version, - gh = gh, date = date, author = author) + data <- lapply(results, maintainer_data, + pkg = pkg, version = version, + gh = gh, date = date, author = author + ) bodies <- lapply(data, whisker::whisker.render, template = template) subjects <- lapply(data, function(x) { - paste0(x$your_package, " and " , x$my_package, " ", x$my_version, " release") + paste0(x$your_package, " and ", x$my_package, " ", x$my_version, " release") }) emails <- Map(maintainer_email, maintainers, bodies, subjects) @@ -63,8 +65,9 @@ revdep_email <- function(pkg = ".", date, message("Testing first email") send_email(emails[[1]], draft = TRUE) - if (yesno("Did first draft email look ok?")) + if (yesno("Did first draft email look ok?")) { return(invisible()) + } sent <- vapply(emails, send_email, draft = draft, FUN.VALUE = logical(1)) @@ -81,20 +84,19 @@ revdep_email <- function(pkg = ".", date, send_email <- function(email, draft = TRUE) { send <- if (draft) gmailr::create_draft else gmailr::send_message msg <- if (draft) "Drafting" else "Sending" - tryCatch( - { - message(msg, ": ", gmailr::subject(email)) - send(email) - TRUE - }, - interrupt = function(e) { - message("Aborted by user") - invokeRestart("abort") - }, - error = function(e) { - message("Failed") - FALSE - } + tryCatch({ + message(msg, ": ", gmailr::subject(email)) + send(email) + TRUE + }, + interrupt = function(e) { + message("Aborted by user") + invokeRestart("abort") + }, + error = function(e) { + message("Failed") + FALSE + } ) } diff --git a/R/revdep-summarise.R b/R/revdep-summarise.R index 892c5fdc8..27e775fa9 100644 --- a/R/revdep-summarise.R +++ b/R/revdep-summarise.R @@ -79,7 +79,8 @@ revdep_check_results_md <- function(results, has_problem) { summary_table <- paste0( paste0(revdep_check_results_kable(results), collapse = "\n"), - "\n\n") + "\n\n" + ) summaries <- vapply(results, format, character(1)) diff --git a/R/revdep.R b/R/revdep.R index 490f69137..68b7af5ff 100755 --- a/R/revdep.R +++ b/R/revdep.R @@ -29,7 +29,7 @@ #' revdep("ggplot2") #' #' revdep("ggplot2", ignore = c("xkcd", "zoo")) -#'} +#' } revdep <- function(pkg, dependencies = c("Depends", "Imports", "Suggests", "LinkingTo"), recursive = FALSE, ignore = NULL, @@ -90,7 +90,8 @@ revdep_check <- function(pkg = ".", recursive = FALSE, ignore = NULL, stop("Cache file `revdep/.cache.rds` exists.\n", "Use `revdep_check_resume()` to resume\n", "Use `revdep_check_reset()` to start afresh.", - call. = FALSE) + call. = FALSE + ) } cat_rule( @@ -105,7 +106,8 @@ revdep_check <- function(pkg = ".", recursive = FALSE, ignore = NULL, } if (dir.exists(check_dir) && length(dir(check_dir, all.files = TRUE, no.. = TRUE)) > 0) { stop("`check_dir()` must not already exist: it is deleted after a successful run", - call. = FALSE) + call. = FALSE + ) } if (is.null(install_dir)) { @@ -114,8 +116,10 @@ revdep_check <- function(pkg = ".", recursive = FALSE, ignore = NULL, } message("Computing reverse dependencies... ") - revdeps <- revdep(pkg$package, recursive = recursive, ignore = ignore, - bioconductor = bioconductor, dependencies = dependencies) + revdeps <- revdep(pkg$package, + recursive = recursive, ignore = ignore, + bioconductor = bioconductor, dependencies = dependencies + ) # Save arguments and revdeps to a cache cache <- list( @@ -314,7 +318,8 @@ cran_packages <- memoise::memoise( function() { local <- file.path(tempdir(), "packages.rds") utils::download.file("http://cran.R-project.org/web/packages/packages.rds", local, - mode = "wb", quiet = TRUE) + mode = "wb", quiet = TRUE + ) on.exit(unlink(local)) cp <- readRDS(local) rownames(cp) <- unname(cp[, 1]) diff --git a/R/run-examples.r b/R/run-examples.r index b4a947b3e..b72d9ea76 100644 --- a/R/run-examples.r +++ b/R/run-examples.r @@ -33,8 +33,9 @@ run_examples <- function(pkg = ".", start = NULL, show = TRUE, test = FALSE, if (fresh) { to_run <- eval(substitute( - function() devtools::run_examples(pkg = path, start = start, test = test, run = run, fresh = FALSE), - list(path = pkg$path, start = start, test = test, run = run))) + function() devtools::run_examples(pkg = path, start = start, test = test, run = run, fresh = FALSE), + list(path = pkg$path, start = start, test = test, run = run) + )) callr::r(to_run, show = TRUE, spinner = FALSE) return(invisible()) } @@ -48,8 +49,9 @@ run_examples <- function(pkg = ".", start = NULL, show = TRUE, test = FALSE, } files <- rd_files(pkg$path, start = start) - if (length(files) == 0) + if (length(files) == 0) { return() + } cat_rule( left = paste0("Running ", length(files), " example files"), diff --git a/R/run-source.r b/R/run-source.r index 902078f7b..78c077f47 100644 --- a/R/run-source.r +++ b/R/run-source.r @@ -52,7 +52,9 @@ source_url <- function(url, ..., sha1 = NULL) { if (!identical(file_sha1, sha1)) { stop("SHA-1 hash of downloaded file (", file_sha1, - ")\n does not match expected value (", sha1, ")", call. = FALSE) + ")\n does not match expected value (", sha1, ")", + call. = FALSE + ) } } @@ -137,7 +139,6 @@ find_gist <- function(id, filename) { if (is.na(which)) { stop("'", filename, "' not found in this gist", call. = FALSE) } - } else { if (length(r_files) > 1) { warning("Multiple R files in gist, using first", call. = FALSE) diff --git a/R/session-info.r b/R/session-info.r index e2b0627bb..2af8e35bf 100644 --- a/R/session-info.r +++ b/R/session-info.r @@ -4,7 +4,6 @@ #' @return A data frame with columns package and path, giving the name of #' each package and the path it was loaded from. loaded_packages <- function() { - attached <- data.frame( package = search(), path = searchpaths(), @@ -21,8 +20,10 @@ loaded_packages <- function() { #' @export #' @keywords internal dev_packages <- function() { - packages <- vapply(loadedNamespaces(), - function(x) !is.null(pkgload::dev_meta(x)), logical(1)) + packages <- vapply( + loadedNamespaces(), + function(x) !is.null(pkgload::dev_meta(x)), logical(1) + ) names(packages)[packages] } diff --git a/R/show-news.r b/R/show-news.r index 84d169faa..a176307e7 100644 --- a/R/show-news.r +++ b/R/show-news.r @@ -18,8 +18,10 @@ show_news <- function(pkg = ".", latest = TRUE, ...) { if (latest) { ver <- numeric_version(out$Version) recent <- ver == max(ver) - structure(out[recent, ], class = class(out), - bad = attr(out, "bad")[recent]) + structure(out[recent, ], + class = class(out), + bad = attr(out, "bad")[recent] + ) } else { out } diff --git a/R/source.r b/R/source.r index d0cb6dc73..22ab40e09 100644 --- a/R/source.r +++ b/R/source.r @@ -5,7 +5,8 @@ source_many <- function(files, envir = parent.frame()) { oop <- options( keep.source = TRUE, show.error.locations = TRUE, - topLevelEnvironment = as.environment(envir)) + topLevelEnvironment = as.environment(envir) + ) on.exit(options(oop)) for (file in files) { @@ -20,7 +21,8 @@ source_one <- function(file, envir = parent.frame()) { lines <- readLines(file, warn = FALSE) srcfile <- srcfilecopy(file, lines, file.info(file)[1, "mtime"], - isFile = TRUE) + isFile = TRUE + ) exprs <- parse(text = lines, n = -1, srcfile = srcfile) n <- length(exprs) diff --git a/R/spell-check.R b/R/spell-check.R index efd874194..ab6d7f39b 100644 --- a/R/spell-check.R +++ b/R/spell-check.R @@ -14,7 +14,7 @@ #' \code{\link{as.package}} for more information #' @param vignettes include vignettes in the spell check; passed to #' \link[spelling:spell_check_package]{spelling::spell_check_package} -spell_check <- function(pkg = ".", vignettes = TRUE){ +spell_check <- function(pkg = ".", vignettes = TRUE) { pkg <- as.package(pkg) spelling::spell_check_package(pkg = pkg, vignettes = vignettes) } diff --git a/R/system.r b/R/system.r index f1147ce22..189424903 100644 --- a/R/system.r +++ b/R/system.r @@ -21,7 +21,8 @@ system_check <- function(cmd, args = character(), env_vars = character(), message() } - result <- suppressWarnings(withr::with_dir(path, withr::with_envvar(env_vars, + result <- suppressWarnings(withr::with_dir(path, withr::with_envvar( + env_vars, system(full, intern = quiet, ignore.stderr = quiet, ...) ))) @@ -52,12 +53,14 @@ system2_check <- function(cmd, args = character(), env_vars = character(), message() } - if (quiet) + if (quiet) { std <- TRUE - else + } else { std <- "" + } - result <- suppressWarnings(withr::with_dir(path, withr::with_envvar(env_vars, + result <- suppressWarnings(withr::with_dir(path, withr::with_envvar( + env_vars, system2(cmd, args, stdout = std, stderr = std, ...) ))) @@ -95,10 +98,13 @@ system_output <- function(cmd, args = character(), env_vars = character(), message(wrap_command(full), "\n") } - result <- withCallingHandlers(withr::with_dir(path, - withr::with_envvar(env_vars, - system(full, intern = TRUE, ignore.stderr = quiet, ...) - )), warning = function(w) stop(w)) + result <- withCallingHandlers(withr::with_dir( + path, + withr::with_envvar( + env_vars, + system(full, intern = TRUE, ignore.stderr = quiet, ...) + ) + ), warning = function(w) stop(w)) result } diff --git a/R/test.r b/R/test.r index 53f1af514..c55ed8ccd 100644 --- a/R/test.r +++ b/R/test.r @@ -47,8 +47,9 @@ test <- function(pkg = ".", filter = NULL, ...) { # Update package dependency to avoid explicit require() call (#798) if (pkg$package != "testthat") { pkg$depends <- paste0("testthat, ", pkg$depends) - if (grepl("^testthat, *$", pkg$depends)) + if (grepl("^testthat, *$", pkg$depends)) { pkg$depends <- "testthat" + } } # Run tests in a child of the namespace environment, like @@ -57,7 +58,8 @@ test <- function(pkg = ".", filter = NULL, ...) { ns_env <- load_all(pkg$path, quiet = TRUE)$env message("Testing ", pkg$package) - Sys.sleep(0.05); utils::flush.console() # Avoid misordered output in RStudio + Sys.sleep(0.05) + utils::flush.console() # Avoid misordered output in RStudio env <- new.env(parent = ns_env) @@ -68,8 +70,10 @@ test <- function(pkg = ".", filter = NULL, ...) { testthat_args <- c(testthat_args, load_helpers = FALSE) } - withr::with_options(c(useFancyQuotes = FALSE), - withr::with_envvar(r_env_vars(), + withr::with_options( + c(useFancyQuotes = FALSE), + withr::with_envvar( + r_env_vars(), do.call(testthat::test_dir, testthat_args) ) ) @@ -87,7 +91,8 @@ test_coverage <- function(pkg = ".", show_report = interactive(), ...) { rstudioapi::documentSaveAll() } - withr::with_envvar(r_env_vars(), + withr::with_envvar( + r_env_vars(), coverage <- covr::package_coverage(pkg$path, ...) ) @@ -151,8 +156,10 @@ test_file <- function(file = find_active_file(), ...) { has_r_ext <- grepl("\\.[rR]$", file) if (any(!has_r_ext)) { stop("file(s): ", - paste0("'", file[!has_r_ext], "'", collapse = ", "), - " are not R files", call. = FALSE) + paste0("'", file[!has_r_ext], "'", collapse = ", "), + " are not R files", + call. = FALSE + ) } file <- basename(file) @@ -208,17 +215,20 @@ test_coverage_file <- function(file = find_active_file(), filter = TRUE, show_re source_files <- normalizePath(winslash = "/", mustWork = FALSE, c( vapply(file[!is_source_file], find_source_file, character(1)), - file[is_source_file])) + file[is_source_file] + )) test_files <- normalizePath(winslash = "/", mustWork = FALSE, c( vapply(file[is_source_file], find_test_file, character(1)), - file[!is_source_file])) + file[!is_source_file] + )) pkg <- as.package(dirname(file)[[1]]) env <- load_all(pkg$path, quiet = TRUE)$env - withr::with_envvar(r_env_vars(), + withr::with_envvar( + r_env_vars(), withr::with_dir("tests/testthat", { coverage <- covr::environment_coverage(env, test_files, ...) }) diff --git a/R/uninstall.r b/R/uninstall.r index 7e795b6f0..85485355c 100644 --- a/R/uninstall.r +++ b/R/uninstall.r @@ -13,7 +13,6 @@ #' @seealso \code{\link{with_debug}} to install packages with debugging flags #' set. uninstall <- function(pkg = ".", unload = TRUE, quiet = FALSE, ...) { - pkg <- as.package(pkg) if (unload && pkg$package %in% loaded_packages()$package) { diff --git a/R/upload-ftp.r b/R/upload-ftp.r index c07160d3c..057a4cde4 100644 --- a/R/upload-ftp.r +++ b/R/upload-ftp.r @@ -1,4 +1,4 @@ -upload_ftp <- function(file, url, verbose = FALSE){ +upload_ftp <- function(file, url, verbose = FALSE) { check_suggested("curl") stopifnot(file.exists(file)) @@ -6,7 +6,7 @@ upload_ftp <- function(file, url, verbose = FALSE){ con <- file(file, open = "rb") on.exit(close(con)) h <- curl::new_handle(upload = TRUE, filetime = FALSE) - curl::handle_setopt(h, readfunction = function(n){ + curl::handle_setopt(h, readfunction = function(n) { readBin(con, raw(), n = n) }, verbose = verbose) curl::curl_fetch_memory(url, handle = h) diff --git a/R/utils.r b/R/utils.r index 906aab538..5ea54cd5a 100644 --- a/R/utils.r +++ b/R/utils.r @@ -165,9 +165,9 @@ last <- function(x) x[length(x)] # after the last '.', as in "foo.tar.gz" => ".gz", if the text that directly # precedes the last '.' is ".tar", it will include also, so # "foo.tar.gz" => ".tar.gz" -file_ext <- function (x) { - pos <- regexpr("\\.((tar\\.)?[[:alnum:]]+)$", x) - ifelse(pos > -1L, substring(x, pos + 1L), "") +file_ext <- function(x) { + pos <- regexpr("\\.((tar\\.)?[[:alnum:]]+)$", x) + ifelse(pos > -1L, substring(x, pos + 1L), "") } is_bioconductor <- function(x) { @@ -191,7 +191,7 @@ indent <- function(x, spaces = 4) { is_windows <- isTRUE(.Platform$OS.type == "windows") -all_named <- function (x) { +all_named <- function(x) { if (length(x) == 0) return(TRUE) !is.null(names(x)) && all(names(x) != "") } @@ -217,14 +217,16 @@ is_attached <- function(pkg = ".") { } # This is base::trimws from 3.2 on -trim_ws <- function (x, which = c("both", "left", "right")) { - which <- match.arg(which) - mysub <- function(re, x) sub(re, "", x, perl = TRUE) - if (which == "left") - return(mysub("^[ \t\r\n]+", x)) - if (which == "right") - return(mysub("[ \t\r\n]+$", x)) - mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) +trim_ws <- function(x, which = c("both", "left", "right")) { + which <- match.arg(which) + mysub <- function(re, x) sub(re, "", x, perl = TRUE) + if (which == "left") { + return(mysub("^[ \t\r\n]+", x)) + } + if (which == "right") { + return(mysub("[ \t\r\n]+$", x)) + } + mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) } # throws a warning if the argument is not the current directory. diff --git a/R/vignette-r.r b/R/vignette-r.r index 532c9a224..4ff236794 100644 --- a/R/vignette-r.r +++ b/R/vignette-r.r @@ -46,8 +46,10 @@ copy_vignettes <- function(pkg, keep_md) { extra_files <- find_vignette_extras(pkg) if (length(extra_files) == 0) return(invisible()) - message("Copying extra files ", paste(basename(extra_files), collapse = ", "), - " to doc/") + message( + "Copying extra files ", paste(basename(extra_files), collapse = ", "), + " to doc/" + ) file.copy(extra_files, doc_dir, recursive = TRUE) invisible() @@ -63,8 +65,10 @@ find_vignette_extras <- function(pkg = ".") { if (length(extras) == 0) return(character()) withr::with_dir(vig_path, { - allfiles <- dir(all.files = TRUE, full.names = TRUE, recursive = TRUE, - include.dirs = TRUE) + allfiles <- dir( + all.files = TRUE, full.names = TRUE, recursive = TRUE, + include.dirs = TRUE + ) }) inst <- rep(FALSE, length(allfiles)) diff --git a/R/vignettes.r b/R/vignettes.r index 80540779f..1efca008e 100644 --- a/R/vignettes.r +++ b/R/vignettes.r @@ -33,8 +33,7 @@ build_vignettes <- function(pkg = ".", upgrade = TRUE, quiet = TRUE, install = TRUE, - keep_md = TRUE - ) { + keep_md = TRUE) { pkg <- as.package(pkg) vigns <- tools::pkgVignettes(dir = pkg$path) if (length(vigns$docs) == 0) return() @@ -48,7 +47,7 @@ build_vignettes <- function(pkg = ".", withr::with_temp_libpaths(action = "prefix", { devtools::install(pkg_path, upgrade_dependencies = upgrade, reload = FALSE, quiet = quiet) tools::buildVignettes(dir = pkg_path, clean = clean, tangle = TRUE, quiet = quiet) - }) + }) } } else { build <- function(pkg_path, clean, quiet, upgrade) { @@ -60,7 +59,8 @@ build_vignettes <- function(pkg = ".", build, args = list(pkg_path = pkg$path, clean = clean, upgrade = upgrade, quiet = quiet), show = TRUE, - spinner = FALSE) + spinner = FALSE + ) # We need to re-run pkgVignettes now that they are built to get the output # files as well @@ -74,7 +74,6 @@ build_vignettes <- function(pkg = ".", } create_vignette_index <- function(pkg, vigns) { - usethis_use_directory(pkg, "Meta", ignore = TRUE) usethis_use_git_ignore(pkg, "Meta") diff --git a/R/zzz.r b/R/zzz.r index 176bd8ee4..adc8e72e8 100644 --- a/R/zzz.r +++ b/R/zzz.r @@ -47,20 +47,20 @@ NULL NULL devtools_default_options <- list( - devtools.path = "~/R-dev", - devtools.install.args = "", - devtools.name = "Your name goes here", - devtools.desc.author = 'person("First", "Last", email = "first.last@example.com", role = c("aut", "cre"))', - devtools.desc.license = "What license is it under?", - devtools.desc.suggests = NULL, - devtools.desc = list(), - devtools.revdep.libpath = file.path(tempdir(), "R-lib") - ) + devtools.path = "~/R-dev", + devtools.install.args = "", + devtools.name = "Your name goes here", + devtools.desc.author = 'person("First", "Last", email = "first.last@example.com", role = c("aut", "cre"))', + devtools.desc.license = "What license is it under?", + devtools.desc.suggests = NULL, + devtools.desc = list(), + devtools.revdep.libpath = file.path(tempdir(), "R-lib") +) .onLoad <- function(libname, pkgname) { op <- options() toset <- !(names(devtools_default_options) %in% names(op)) - if(any(toset)) options(devtools_default_options[toset]) + if (any(toset)) options(devtools_default_options[toset]) invisible() } diff --git a/tests/testthat/helper-github.R b/tests/testthat/helper-github.R index c71f36847..6855d878f 100644 --- a/tests/testthat/helper-github.R +++ b/tests/testthat/helper-github.R @@ -1,6 +1,6 @@ ## set-up and tear-down create_in_temp <- function(pkg) { - temp_path <- tempfile(pattern="devtools-test-") + temp_path <- tempfile(pattern = "devtools-test-") dir.create(temp_path) test_pkg <- file.path(temp_path, pkg) capture.output(suppressMessages(usethis::create_package(test_pkg, fields = list()))) @@ -19,8 +19,10 @@ mock_use_github <- function(pkg) { # TODO:(jimhester) Remove withr::with_dir once # https://github.com/r-lib/usethis/commit/9d91022aab2d5f58952cb7852000500dd22a07a0 # is on CRAN - withr::with_output_sink("ignore", - withr::with_dir(pkg, usethis::use_github_links())) + withr::with_output_sink( + "ignore", + withr::with_dir(pkg, usethis::use_github_links()) + ) unlink("ignore") git2r::add(r, "DESCRIPTION") git2r::commit(r, "Add GitHub links to DESCRIPTION") diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 04e886dc3..236609278 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -1,5 +1,4 @@ skip_if_offline <- function(host = "httpbin.org", port = 80) { - res <- tryCatch( pingr::ping_port(host, count = 1L, port = port), error = function(e) NA diff --git a/tests/testthat/test-bioconductor.r b/tests/testthat/test-bioconductor.r index 892d017cb..482eabc08 100644 --- a/tests/testthat/test-bioconductor.r +++ b/tests/testthat/test-bioconductor.r @@ -1,12 +1,12 @@ context("bioc") test_that("bioc repo paths are parsed correctly", { - expect_equal(parse_bioc_repo("devtools#abc123"), list(repo="devtools", commit="abc123")) - expect_equal(parse_bioc_repo("user:pass@devtools"), list(username = "user", password = "pass", repo="devtools")) - expect_equal(parse_bioc_repo("devel/devtools"), list(release = "devel", repo="devtools")) - expect_equal(parse_bioc_repo("3.1/devtools"), list(release = "3.1", repo="devtools")) - expect_equal(parse_bioc_repo("release/devtools"), list(release = "release", repo="devtools")) - expect_equal(parse_bioc_repo("user:pass@devtools#abc123"), list(username = "user", password = "pass", repo="devtools", commit = "abc123")) + expect_equal(parse_bioc_repo("devtools#abc123"), list(repo = "devtools", commit = "abc123")) + expect_equal(parse_bioc_repo("user:pass@devtools"), list(username = "user", password = "pass", repo = "devtools")) + expect_equal(parse_bioc_repo("devel/devtools"), list(release = "devel", repo = "devtools")) + expect_equal(parse_bioc_repo("3.1/devtools"), list(release = "3.1", repo = "devtools")) + expect_equal(parse_bioc_repo("release/devtools"), list(release = "release", repo = "devtools")) + expect_equal(parse_bioc_repo("user:pass@devtools#abc123"), list(username = "user", password = "pass", repo = "devtools", commit = "abc123")) expect_error(parse_bioc_repo("user:pass@3.1/devtools#abc123"), "release and commit should not both be specified") expect_error(parse_bioc_repo("user@devtools"), "Invalid bioc repo") expect_error(parse_bioc_repo("user:@devtools"), "Invalid bioc repo") diff --git a/tests/testthat/test-build-site.R b/tests/testthat/test-build-site.R index 0bc8923f1..89c562853 100644 --- a/tests/testthat/test-build-site.R +++ b/tests/testthat/test-build-site.R @@ -4,22 +4,28 @@ test_that("Package pkgdown site can be built ", { destination <- file.path(tempdir(), "testPkgdown", "docs") build_output <- capture.output({ - build_site(path = "./testPkgdown", - override = list(destination = destination)) + build_site( + path = "./testPkgdown", + override = list(destination = destination) + ) }, type = c("output")) build_output <- paste(build_output, collapse = "\n") expect_true(file.exists(file.path(destination, "index.html")), - info = build_output, - label = "created site index") + info = build_output, + label = "created site index" + ) expect_true(file.exists(file.path(destination, "reference", "index.html")), - info = build_output, - label = "created reference index") + info = build_output, + label = "created reference index" + ) expect_true(file.exists(file.path(destination, "articles", "index.html")), - info = build_output, - label = "created articles index") + info = build_output, + label = "created articles index" + ) expect_true(file.exists(file.path(destination, "articles", "test.html")), - info = build_output, - label = "created articles index") + info = build_output, + label = "created articles index" + ) }) diff --git a/tests/testthat/test-examples.R b/tests/testthat/test-examples.R index 988ce4a1d..e0e02bdf4 100644 --- a/tests/testthat/test-examples.R +++ b/tests/testthat/test-examples.R @@ -1,6 +1,6 @@ -context('Examples') +context("Examples") -test_that('Can run an example', { +test_that("Can run an example", { pkg <- "testHelp" - expect_output(run_examples(pkg = pkg, document = FALSE), "You called foofoo.", fixed=TRUE) + expect_output(run_examples(pkg = pkg, document = FALSE), "You called foofoo.", fixed = TRUE) }) diff --git a/tests/testthat/test-github-connections.R b/tests/testthat/test-github-connections.R index 77dae7497..f89df7ca9 100644 --- a/tests/testthat/test-github-connections.R +++ b/tests/testthat/test-github-connections.R @@ -6,16 +6,21 @@ test_that("git (non-)usage is detected, diagnosed, and can be added", { test_pkg <- create_in_temp("testNoGit") expect_false(uses_git(test_pkg)) - expect_warning(expect_message(print(dr_github(test_pkg)), - "not a git repository"), - 'DR_GITHUB FOUND PROBLEMS') - - expect_message(use_git_with_config(message = "initial", pkg = test_pkg, add_user_config = TRUE), - "Initialising repo") + expect_warning( + expect_message( + print(dr_github(test_pkg)), + "not a git repository" + ), + "DR_GITHUB FOUND PROBLEMS" + ) + + expect_message( + use_git_with_config(message = "initial", pkg = test_pkg, add_user_config = TRUE), + "Initialising repo" + ) expect_true(uses_git(test_pkg)) erase(test_pkg) - }) test_that("GitHub non-usage is handled", { @@ -26,16 +31,19 @@ test_that("GitHub non-usage is handled", { expect_true(uses_git(test_pkg)) expect_false(uses_github(test_pkg)) - expect_warning(expect_message(print(dr_github(test_pkg)), - "not a GitHub repository"), - "DR_GITHUB FOUND PROBLEMS") + expect_warning( + expect_message( + print(dr_github(test_pkg)), + "not a GitHub repository" + ), + "DR_GITHUB FOUND PROBLEMS" + ) expect_identical(github_dummy, github_info(test_pkg)) expect_error(usethis::use_github_links(), "Cannot detect .* GitHub") erase(test_pkg) - }) ## If env var GITHUB_PAT exists and there's willingness to call GitHub @@ -58,12 +66,20 @@ test_that("github info and links can be queried and manipulated", { desc <- read_dcf(desc_path) ## default GitHub links created by use_github_links() via use_github() - expect_identical(desc[["URL"]], - file.path("https://github.com", - gh_info$username, gh_info$repo)) - expect_identical(desc[["BugReports"]], - file.path("https://github.com", - gh_info$username, gh_info$repo, "issues")) + expect_identical( + desc[["URL"]], + file.path( + "https://github.com", + gh_info$username, gh_info$repo + ) + ) + expect_identical( + desc[["BugReports"]], + file.path( + "https://github.com", + gh_info$username, gh_info$repo, "issues" + ) + ) ## make sure we don't clobber existing links mtime_before <- file.info(desc_path)$mtime @@ -74,15 +90,22 @@ test_that("github info and links can be queried and manipulated", { desc$URL <- "http://www.example.com" desc$BugReports <- "http://www.example.com/issues" write_dcf(desc_path, desc) - expect_warning(expect_message(print(dr_github(test_pkg)), - "no GitHub repo link"), - "DR_GITHUB FOUND PROBLEMS") - expect_warning(expect_message(print(dr_github(test_pkg)), - "no GitHub Issues"), - "DR_GITHUB FOUND PROBLEMS") + expect_warning( + expect_message( + print(dr_github(test_pkg)), + "no GitHub repo link" + ), + "DR_GITHUB FOUND PROBLEMS" + ) + expect_warning( + expect_message( + print(dr_github(test_pkg)), + "no GitHub Issues" + ), + "DR_GITHUB FOUND PROBLEMS" + ) erase(test_pkg) - }) test_that("github_info() prefers, but doesn't require, remote named 'origin'", { @@ -92,8 +115,10 @@ test_that("github_info() prefers, but doesn't require, remote named 'origin'", { mock_use_github(test_pkg) r <- git2r::repository(test_pkg, discover = TRUE) - git2r::remote_add(r, "anomaly", - "https://github.com/twitter/AnomalyDetection.git") + git2r::remote_add( + r, "anomaly", + "https://github.com/twitter/AnomalyDetection.git" + ) ## defaults to "origin" expect_equal(github_info(test_pkg)$username, "r-lib") @@ -115,12 +140,13 @@ test_that("github_info() prefers, but doesn't require, remote named 'origin'", { expect_error(github_info(test_pkg, remote_name = "nope")) erase(test_pkg) - }) test_that("username and repo are extracted from github remote URL", { - gh_info <- list(username = "r-lib", repo = "devtools", - fullname = "r-lib/devtools") + gh_info <- list( + username = "r-lib", repo = "devtools", + fullname = "r-lib/devtools" + ) expect_identical(github_remote_parse("https://github.com/r-lib/devtools.git"), gh_info) expect_identical(github_remote_parse("https://github.com/r-lib/devtools"), gh_info) expect_identical(github_remote_parse("git@github.com:r-lib/devtools.git"), gh_info) diff --git a/tests/testthat/test-github.r b/tests/testthat/test-github.r index 54ecf3b96..93be8f93e 100644 --- a/tests/testthat/test-github.r +++ b/tests/testthat/test-github.r @@ -11,13 +11,13 @@ with_mock <- function(name, value, code) { } test_that("GitHub repo paths are parsed correctly", { - expect_equal(parse_git_repo("devtools"), list(repo="devtools")) - expect_equal(parse_git_repo("krlmlr/kimisc"), list(username="krlmlr", repo="kimisc")) - expect_equal(parse_git_repo("my/test/pkg"), list(username="my", repo="test", subdir="pkg")) - expect_equal(parse_git_repo("devtools@devtools-1.4"), list(repo="devtools", ref="devtools-1.4")) - expect_equal(parse_git_repo("yihui/tikzDevice#23"), list(username="yihui", repo="tikzDevice", ref=github_pull("23"))) - expect_equal(parse_git_repo("my/test/pkg@ref"), list(username="my", repo="test", subdir="pkg", ref="ref")) - expect_equal(parse_git_repo("my/test/pkg#1"), list(username="my", repo="test", subdir="pkg", ref=github_pull("1"))) + expect_equal(parse_git_repo("devtools"), list(repo = "devtools")) + expect_equal(parse_git_repo("krlmlr/kimisc"), list(username = "krlmlr", repo = "kimisc")) + expect_equal(parse_git_repo("my/test/pkg"), list(username = "my", repo = "test", subdir = "pkg")) + expect_equal(parse_git_repo("devtools@devtools-1.4"), list(repo = "devtools", ref = "devtools-1.4")) + expect_equal(parse_git_repo("yihui/tikzDevice#23"), list(username = "yihui", repo = "tikzDevice", ref = github_pull("23"))) + expect_equal(parse_git_repo("my/test/pkg@ref"), list(username = "my", repo = "test", subdir = "pkg", ref = "ref")) + expect_equal(parse_git_repo("my/test/pkg#1"), list(username = "my", repo = "test", subdir = "pkg", ref = github_pull("1"))) expect_error(parse_git_repo("test#6@123"), "Invalid git repo") expect_error(parse_git_repo("Teradata/teradataR/"), "Invalid git repo") expect_error(parse_git_repo("test@*unsupported-release"), "Invalid git repo") @@ -32,7 +32,7 @@ mock_github_resolve_ref.github_pull <- function(x, params, ...) { # Mock github_resolve_ref.github_release so that GitHub API is not queried for this test mock_github_resolve_ref.github_release <- function(x, params, ...) { - params$ref="latest-release" + params$ref <- "latest-release" params } @@ -53,15 +53,16 @@ test_that("GitHub parameters are returned correctly", { mock_github_GET <- function(path, pat, host) { if (grepl("^repos/.*/pulls/.*$", path)) { - list(head=list(user=list(login="username"), ref="some-pull-request")) + list(head = list(user = list(login = "username"), ref = "some-pull-request")) } else if (grepl("^repos/.*/releases$", path)) { - list(list(tag_name="some-release")) - } else + list(list(tag_name = "some-release")) + } else { stop("unexpected path: ", path) + } } test_that("GitHub references are resolved correctly", { - default_params <- as.list(stats::setNames(nm=c("repo", "username"))) + default_params <- as.list(stats::setNames(nm = c("repo", "username"))) with_mock("github_GET", mock_github_GET, { expect_equal(github_resolve_ref(NULL, list())$ref, "master") expect_equal(github_resolve_ref("some-ref", list())$ref, "some-ref") diff --git a/tests/testthat/test-install-gitlab.R b/tests/testthat/test-install-gitlab.R index d8cb61d85..d4447aec8 100644 --- a/tests/testthat/test-install-gitlab.R +++ b/tests/testthat/test-install-gitlab.R @@ -1,7 +1,6 @@ context("Install from GitLab") test_that("install_gitlab", { - skip_on_cran() skip_if_offline() @@ -19,11 +18,11 @@ test_that("install_gitlab", { expect_silent(packageDescription("falsy", lib.loc = lib)) expect_equal( packageDescription("falsy", lib.loc = lib)$RemoteRepo, - "falsy") + "falsy" + ) }) test_that("error if not username, warning if given as argument", { - skip_on_cran() skip_if_offline() @@ -39,7 +38,6 @@ test_that("error if not username, warning if given as argument", { }) test_that("remote_download.gitlab_remote messages", { - mockery::stub(remote_download.gitlab_remote, "download_gitlab", TRUE) expect_message( remote_download.gitlab_remote( @@ -55,7 +53,6 @@ test_that("remote_download.gitlab_remote messages", { }) test_that("remote_metadata.gitlab_remote", { - skip_on_cran() skip_if_offline() @@ -70,5 +67,4 @@ test_that("remote_metadata.gitlab_remote", { )$RemoteSha, "0f39d9eb735bf16909831c0bb129063dda388375" ) - }) diff --git a/tests/testthat/test-install-version.R b/tests/testthat/test-install-version.R index c1567fb43..26a0a733b 100644 --- a/tests/testthat/test-install-version.R +++ b/tests/testthat/test-install-version.R @@ -1,10 +1,11 @@ context("Install specific version") local_archive <- function(x) { - if (x == "http://cran.r-project.org") + if (x == "http://cran.r-project.org") { readRDS("archive.rds") - else + } else { NULL + } } test_that("package_find_repo() works correctly with multiple repos", { @@ -16,7 +17,8 @@ test_that("package_find_repo() works correctly with multiple repos", { # ROI.plugin.glpk is the smallest package in the CRAN archive package <- "ROI.plugin.glpk" - with_mock(`devtools:::read_archive` = local_archive, + with_mock( + `devtools:::read_archive` = local_archive, res <- package_find_repo(package, repos = repos) ) @@ -31,7 +33,8 @@ test_that("package_find_repo() works correctly with archived packages", { skip_if_not(getRversion() >= "3.2.0") repos <- c(CRAN = "http://cran.r-project.org") package <- "igraph0" - with_mock(`devtools:::read_archive` = local_archive, + with_mock( + `devtools:::read_archive` = local_archive, res <- package_find_repo(package, repos = repos) ) diff --git a/tests/testthat/test-remote-metadata.R b/tests/testthat/test-remote-metadata.R index 521e117c8..391ee7c4d 100644 --- a/tests/testthat/test-remote-metadata.R +++ b/tests/testthat/test-remote-metadata.R @@ -1,10 +1,8 @@ context("remote-metadata") test_that("pkg_sha metadata from shallow clone", { - - pkg_sha <- git_sha1(path='shallowRepo') - expect_equal(pkg_sha, '21d5d94011') - + pkg_sha <- git_sha1(path = "shallowRepo") + expect_equal(pkg_sha, "21d5d94011") }) @@ -28,8 +26,10 @@ test_that("install on packages adds metadata", { library("testMetadataInstall") pkg_info <- session_info()$packages - expect_equal(pkg_info[pkg_info[, "package"] %in% "testMetadataInstall", "source"], - "local") + expect_equal( + pkg_info[pkg_info[, "package"] %in% "testMetadataInstall", "source"], + "local" + ) # now use default r <- git2r::repository(test_pkg) @@ -58,6 +58,5 @@ test_that("install on packages adds metadata", { pkg_source <- pkg_info[pkg_info[, "package"] %in% "testMetadataInstall", "source"] pkg_sha <- substring(git2r::commits(r)[[1]]$sha, 1, 7) expect_match(pkg_source, pkg_sha) - }) }) diff --git a/tests/testthat/test-remotes.r b/tests/testthat/test-remotes.r index 4cfb320c6..194d6c6ec 100644 --- a/tests/testthat/test-remotes.r +++ b/tests/testthat/test-remotes.r @@ -6,21 +6,31 @@ test_that("remote_deps returns NULL if no remotes specified", { test_that("remote_deps returns works with implicit types", { with_mock(`devtools::package2remote` = function(...) NULL, { - expect_equal(parse_one_remote("hadley/testthat"), - github_remote("hadley/testthat")) - - expect_equal(parse_one_remote("klutometis/roxygen"), - github_remote("klutometis/roxygen")) + expect_equal( + parse_one_remote("hadley/testthat"), + github_remote("hadley/testthat") + ) + + expect_equal( + parse_one_remote("klutometis/roxygen"), + github_remote("klutometis/roxygen") + ) }) - expect_equal(split_remotes("hadley/testthat,klutometis/roxygen"), - c("hadley/testthat", "klutometis/roxygen")) + expect_equal( + split_remotes("hadley/testthat,klutometis/roxygen"), + c("hadley/testthat", "klutometis/roxygen") + ) - expect_equal(split_remotes("hadley/testthat,\n klutometis/roxygen"), - c("hadley/testthat", "klutometis/roxygen")) + expect_equal( + split_remotes("hadley/testthat,\n klutometis/roxygen"), + c("hadley/testthat", "klutometis/roxygen") + ) - expect_equal(split_remotes("hadley/testthat,\n\t klutometis/roxygen"), - c("hadley/testthat", "klutometis/roxygen")) + expect_equal( + split_remotes("hadley/testthat,\n\t klutometis/roxygen"), + c("hadley/testthat", "klutometis/roxygen") + ) }) test_that("split_remotes errors with missing commas", { @@ -30,34 +40,52 @@ test_that("split_remotes errors with missing commas", { }) test_that("dev_remote_type errors", { - expect_error(parse_one_remote(""), - "Malformed remote specification ''") - - expect_error(parse_one_remote("git::testthat::blah"), - "Malformed remote specification 'git::testthat::blah'") - expect_error(parse_one_remote("hadley::testthat"), - "Unknown remote type: hadley") - expect_error(parse_one_remote("SVN2::testthat"), - "Unknown remote type: SVN2") + expect_error( + parse_one_remote(""), + "Malformed remote specification ''" + ) + + expect_error( + parse_one_remote("git::testthat::blah"), + "Malformed remote specification 'git::testthat::blah'" + ) + expect_error( + parse_one_remote("hadley::testthat"), + "Unknown remote type: hadley" + ) + expect_error( + parse_one_remote("SVN2::testthat"), + "Unknown remote type: SVN2" + ) }) test_that("dev_remote_type works with explicit types", { with_mock(`devtools::package2remote` = function(...) NULL, { - expect_equal(parse_one_remote("github::hadley/testthat"), - github_remote("hadley/testthat")) + expect_equal( + parse_one_remote("github::hadley/testthat"), + github_remote("hadley/testthat") + ) }) - expect_equal(split_remotes("github::hadley/testthat,klutometis/roxygen"), - c("github::hadley/testthat", "klutometis/roxygen")) - - expect_equal(split_remotes("hadley/testthat,github::klutometis/roxygen"), - c("hadley/testthat", "github::klutometis/roxygen")) - - expect_equal(split_remotes("github::hadley/testthat,github::klutometis/roxygen"), - c("github::hadley/testthat", "github::klutometis/roxygen")) - - expect_equal(split_remotes("bioc::user:password@release/Biobase#12345,github::klutometis/roxygen"), - c("bioc::user:password@release/Biobase#12345", "github::klutometis/roxygen")) + expect_equal( + split_remotes("github::hadley/testthat,klutometis/roxygen"), + c("github::hadley/testthat", "klutometis/roxygen") + ) + + expect_equal( + split_remotes("hadley/testthat,github::klutometis/roxygen"), + c("hadley/testthat", "github::klutometis/roxygen") + ) + + expect_equal( + split_remotes("github::hadley/testthat,github::klutometis/roxygen"), + c("github::hadley/testthat", "github::klutometis/roxygen") + ) + + expect_equal( + split_remotes("bioc::user:password@release/Biobase#12345,github::klutometis/roxygen"), + c("bioc::user:password@release/Biobase#12345", "github::klutometis/roxygen") + ) }) test_that("different_sha returns TRUE if remote or local sha is NA not found", { @@ -82,15 +110,15 @@ test_that("remote_sha.github_remote returns expected value if remote does exist" }) test_that("package2remotes looks for the DESCRIPTION in .libPaths", { - expect_equal(package2remote("testTest")$sha, NA_character_) - withr::with_temp_libpaths({ - expect_equal(package2remote("testTest")$sha, NA_character_) - install("testTest", quiet = TRUE) - expect_equal(package2remote("testTest")$sha, "0.1") - - # Load the namespace, as packageDescription looks in loaded namespaces - # first. - loadNamespace("testTest") - }) - expect_equal(package2remote("testTest")$sha, NA_character_) + expect_equal(package2remote("testTest")$sha, NA_character_) + withr::with_temp_libpaths({ + expect_equal(package2remote("testTest")$sha, NA_character_) + install("testTest", quiet = TRUE) + expect_equal(package2remote("testTest")$sha, "0.1") + + # Load the namespace, as packageDescription looks in loaded namespaces + # first. + loadNamespace("testTest") + }) + expect_equal(package2remote("testTest")$sha, NA_character_) }) diff --git a/tests/testthat/test-uninstall.r b/tests/testthat/test-uninstall.r index 5d1fe07ac..339cc948f 100644 --- a/tests/testthat/test-uninstall.r +++ b/tests/testthat/test-uninstall.r @@ -4,7 +4,7 @@ test_that("uninstall() unloads and removes from library", { # Make a temp lib directory to install test package into old_libpaths <- .libPaths() - tmp_libpath = file.path(tempdir(), "devtools_test") + tmp_libpath <- file.path(tempdir(), "devtools_test") if (!dir.exists(tmp_libpath)) dir.create(tmp_libpath) .libPaths(c(tmp_libpath, .libPaths())) @@ -19,6 +19,8 @@ test_that("uninstall() unloads and removes from library", { # Uninstall package uninstall("testHelp", quiet = TRUE) expect_false("testHelp" %in% loaded_packages()$package) - expect_warning(expect_false(require(testHelp, quietly = TRUE)), - paste0("there is no package called ", sQuote("testHelp") )) + expect_warning( + expect_false(require(testHelp, quietly = TRUE)), + paste0("there is no package called ", sQuote("testHelp")) + ) }) diff --git a/tests/testthat/test-update.R b/tests/testthat/test-update.R index b25a97a97..16c2f1826 100644 --- a/tests/testthat/test-update.R +++ b/tests/testthat/test-update.R @@ -7,7 +7,6 @@ context("update.package_deps") ## 2 = package not on CRAN test_that("update.package_deps", { - object <- data.frame( stringsAsFactors = FALSE, package = c("dotenv", "falsy", "magrittr"), @@ -55,5 +54,4 @@ test_that("update.package_deps", { "magrittr" ) ) - }) diff --git a/tests/testthat/test-vignettes.r b/tests/testthat/test-vignettes.r index 41c0a4da8..a4ced726f 100644 --- a/tests/testthat/test-vignettes.r +++ b/tests/testthat/test-vignettes.r @@ -85,8 +85,10 @@ test_that("Extra files copied and removed", { pkg <- as.package("testVignetteExtras") doc_path <- file.path(pkg$path, "doc") - extras_path <- file.path("testVignetteExtras", "vignettes", - ".install_extras") + extras_path <- file.path( + "testVignetteExtras", "vignettes", + ".install_extras" + ) writeLines("a.r", extras_path) on.exit(unlink(extras_path)) @@ -106,8 +108,10 @@ test_that("vignettes built on install", { skip("pdflatex not available") } - install("testVignettesBuilt", reload = FALSE, quiet = TRUE, - build_vignettes = TRUE) + install("testVignettesBuilt", + reload = FALSE, quiet = TRUE, + build_vignettes = TRUE + ) unlink("testVignettesBuilt/vignettes/new.tex") unlink("testVignettesBuilt/vignettes/.build.timestamp") diff --git a/tests/testthat/testTest/R/dummy.R b/tests/testthat/testTest/R/dummy.R index e69de29bb..8b1378917 100644 --- a/tests/testthat/testTest/R/dummy.R +++ b/tests/testthat/testTest/R/dummy.R @@ -0,0 +1 @@ + diff --git a/tests/testthat/testUseData/R/a.r b/tests/testthat/testUseData/R/a.r index e69de29bb..8b1378917 100644 --- a/tests/testthat/testUseData/R/a.r +++ b/tests/testthat/testUseData/R/a.r @@ -0,0 +1 @@ +