diff --git a/R/collate.R b/R/collate.R index ce93d01..e551413 100644 --- a/R/collate.R +++ b/R/collate.R @@ -57,7 +57,7 @@ collate <- function(pkg = ".", ...) { # where the return can be a list of file specs lst_spec <- flatten_file_spec(lst_spec) k <- length(lst_spec) - if (k == 0L) stop("Please provide at least one file specification") + if (k == 0L) stop("Must provide at least one file specification.", call. = FALSE) lst_collection <- lapply(seq_len(k), function(i) fs_to_df(path, lst_spec[[i]])) df <- do.call(rbind, lst_collection) # remove duplicates @@ -131,7 +131,7 @@ fs_to_df <- function(pkg_path, file_spec) { #' @noRd flatten_file_spec <- function(lst) { if (!all(sapply(lapply(lst, class), `%in%`, c("file_spec", "list")))) { - stop("Input has objects that are not file specifications") + stop("All inputs must be file specification objects.", call. = FALSE) } do.call(c, lapply(lst, function(x) if (!is_file_spec(x)) flatten_file_spec(x) else list(x))) } @@ -195,7 +195,7 @@ create_fc_df <- function(nrow) { #' @noRd get_pkg_name <- function(path) { path <- paste0(path, "/DESCRIPTION") - if (!file.exists(path)) stop("Package root does not have a DESCRIPTION file") + if (!file.exists(path)) stop("Can't find the `DESCRIPTION` file in package root.", call. = FALSE) desc_file <- normalizePath(path, winslash = "/") pkg_name <- unname(read.dcf(desc_file)[, "Package"]) pkg_name diff --git a/R/collection.R b/R/collection.R index 35e49bb..8dbeb92 100644 --- a/R/collection.R +++ b/R/collection.R @@ -131,11 +131,11 @@ merge.file_collection <- function(x, y, ...) { lst_fc <- list(x, y, ...) if (!all(sapply(lst_fc, is_file_collection))) { - stop("All inputs must be file collection objects") + stop("All inputs must be file collection objects.", call. = FALSE) } pkg_name <- unique(sapply(lst_fc, "[[", "pkg_name")) if (length(pkg_name) != 1L) { - stop("Can only merge file collections for the same package") + stop("Can't merge file collections for different packages.", call. = FALSE) } rbind0 <- function(...) rbind(..., stringsAsFactors = FALSE) @@ -146,7 +146,7 @@ merge.file_collection <- function(x, y, ...) { df <- unique(df) # ensure relative paths are not duplicated if (anyDuplicated(df$"path_rel") != 0L) { - stop("Some files share single relative path but conflicting absolute paths") + stop("Some files share the same relative path but conflicting absolute paths.", call. = FALSE) } new_file_collection(pkg_name, df) @@ -188,7 +188,7 @@ prune.file_collection <- function(x, path) { if (anyNA(idx)) { warning( paste0( - "No matching files in file collection: ", + "Can't find files in file collection: ", paste0(path[is.na(idx)], collapse = ", ") ) ) diff --git a/R/pack.R b/R/pack.R index 4a83188..626dd6e 100644 --- a/R/pack.R +++ b/R/pack.R @@ -68,8 +68,8 @@ pack <- function(..., output, quiet = FALSE) { lst_fc <- list(...) npkgs <- length(lst_fc) pkg_names <- get_fc_pkg(lst_fc) - if (npkgs < 1L) stop("Please provide at least one file collection as input") - if (!all(sapply(lst_fc, is_file_collection))) stop("All inputs must be file collections") + if (npkgs < 1L) stop("Must provide at least one file collection as input.", call. = FALSE) + if (!all(sapply(lst_fc, is_file_collection))) stop("All inputs must be file collection objects.", call. = FALSE) # determine output file name ---- output_default <- if (npkgs > 1L) "pkglite.txt" else tolower(paste0(pkg_names[1L], ".txt")) diff --git a/R/spec.R b/R/spec.R index 1a5b4cd..7297e88 100644 --- a/R/spec.R +++ b/R/spec.R @@ -52,7 +52,7 @@ #' ) file_spec <- function(path, pattern = NULL, format = c("binary", "text"), recursive = TRUE, ignore_case = TRUE, all_files = FALSE) { - if (missing(path)) stop("path cannot be empty") + if (missing(path)) stop("Must provide a non-empty `path`.", call. = FALSE) format <- match.arg(format) lst <- list( diff --git a/R/unpack.R b/R/unpack.R index 4999790..e0ede3b 100644 --- a/R/unpack.R +++ b/R/unpack.R @@ -73,7 +73,7 @@ #' list.files() unpack <- function(input, output = ".", install = FALSE, quiet = FALSE, ...) { # handle input ---- - if (missing(input)) stop("Please provide an input file") + if (missing(input)) stop("Must provide an input file.", call. = FALSE) # read input ---- if (!quiet) cli_h1("Unpacking from pkglite file") @@ -224,7 +224,7 @@ extract_value <- function(x) { #' #' @noRd extract_value_multi <- function(x, start, end) { - if (length(start) != length(end)) stop("start and end must have equal length") + if (length(start) != length(end)) stop("`start` and `end` must have equal length.", call. = FALSE) k <- length(start) lapply(seq_len(k), function(i) substring(x[start[i]:end[i]], 3)) } diff --git a/R/utils.R b/R/utils.R index 987c31f..6dd333d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -48,7 +48,7 @@ #' pack(output = txt, quiet = TRUE) %>% #' verify_ascii() verify_ascii <- function(input, quiet = FALSE) { - if (missing(input)) stop("Please provide an input file") + if (missing(input)) stop("Must provide an input file.", call. = FALSE) input <- file.path(input) x <- suppressMessages(showNonASCIIfile(input)) has_only_ascii <- !as.logical(length(x)) @@ -91,7 +91,7 @@ verify_ascii <- function(input, quiet = FALSE) { #' pack(output = txt, quiet = TRUE) %>% #' remove_content(c("## New Features", "## Improvements"), quiet = TRUE) remove_content <- function(input, x, quiet = FALSE) { - if (missing(input)) stop("Please provide an input file") + if (missing(input)) stop("Must provide an input file.", call. = FALSE) y <- readLines(input) idx_content <- which(substr(y, 1L, 2L) == " ")