From 1e467f582e3e6489252e8091efef99cbf0eb59e7 Mon Sep 17 00:00:00 2001 From: Maximilian Muecke Date: Wed, 1 May 2024 13:07:43 +0200 Subject: [PATCH] refactor: use outer negation, startsWith, and anyNA for more effcient variants --- R/assertions.R | 2 +- R/utils.R | 2 +- R/zip.R | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/assertions.R b/R/assertions.R index de6f41d..e4d9658 100644 --- a/R/assertions.R +++ b/R/assertions.R @@ -4,7 +4,7 @@ is_string <- function(x) { } is_character <- function(x) { - is.character(x) && !any(is.na(x)) + is.character(x) && !anyNA(x) } is_character_or_null <- function(x) { diff --git a/R/utils.R b/R/utils.R index 0322687..78eb8b9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -52,7 +52,7 @@ warn_for_colon <- function(files) { } fix_absolute_paths <- function(files) { - if (any(substr(files, 1, 1) == "/")) { + if (any(startsWith(files, "/"))) { warning("Dropping leading `/` from paths, all paths in a zip file ", "must be relative paths.") files <- sub("^/", "", files) diff --git a/R/zip.R b/R/zip.R index 37d3cc0..33ca54b 100644 --- a/R/zip.R +++ b/R/zip.R @@ -188,7 +188,7 @@ zip_internal <- function(zipfile, files, recurse, compression_level, oldwd <- setwd(root) on.exit(setwd(oldwd), add = TRUE) - if (any(! file.exists(files))) stop("Some files do not exist") + if (!all(file.exists(files))) stop("Some files do not exist") data <- get_zip_data(files, recurse, keep_path, include_directories) data$key <- fix_absolute_paths(data$key)