diff --git a/NAMESPACE b/NAMESPACE index 2d04018..6ff735e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -73,6 +73,9 @@ export(warningp) export(zipit) exportPattern("^[[:alpha:]]+") importFrom(Rcpp,evalCpp) +importFrom(assertthat,assert_that) +importFrom(assertthat,is.flag) +importFrom(assertthat,is.string) importFrom(dplyr,"%>%") importFrom(methods,is) importFrom(rlang,"!!") diff --git a/R/FastUtils-package.R b/R/FastUtils-package.R index e049764..5888ad7 100644 --- a/R/FastUtils-package.R +++ b/R/FastUtils-package.R @@ -8,6 +8,7 @@ #' @importFrom rlang !! #' @importFrom methods is #' @importFrom Rcpp evalCpp +#' @importFrom assertthat assert_that is.flag is.string #' @useDynLib FastUtils, .registration = TRUE ## usethis namespace: end NULL diff --git a/R/character.R b/R/character.R index b3fb910..8eac5b9 100644 --- a/R/character.R +++ b/R/character.R @@ -20,9 +20,9 @@ #' substrEnd("12345", 2, 3) #' substrEnd <- function(x, start, endDiff) { - assertthat::assert_that(is.character(x)) - assertthat::assert_that(is.numeric(start)) - assertthat::assert_that(is.numeric(endDiff)) + assert_that(is.character(x)) + assert_that(is.numeric(start)) + assert_that(is.numeric(endDiff)) substr(x, start, nchar(x) - endDiff) } @@ -41,9 +41,9 @@ substrEnd <- function(x, start, endDiff) { #' @examples #' enclose("text", "[", "]") # returns "[text]" enclose <- function(x, left, right) { - assertthat::assert_that(is.character(x)) - assertthat::assert_that(is.character(left)) - assertthat::assert_that(is.character(right)) + assert_that(is.character(x)) + assert_that(is.character(left)) + assert_that(is.character(right)) paste0(left, x, right) } @@ -59,7 +59,7 @@ enclose <- function(x, left, right) { #' @examples #' encloseBr("text") # returns "(text)" encloseBr <- function(x) { - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) enclose(x, "(", ")") } @@ -81,8 +81,8 @@ encloseBr <- function(x) { #' getChar("hello", 2) getChar <- function(x, index) { - assertthat::assert_that(is.character(x)) - assertthat::assert_that( + assert_that(is.character(x)) + assert_that( is.numeric(index) && (length(index) == length(x) || length(index) == 1) ) diff --git a/R/dataInitialization.R b/R/dataInitialization.R index aa165b1..5a87806 100644 --- a/R/dataInitialization.R +++ b/R/dataInitialization.R @@ -132,7 +132,7 @@ tableToNumeric <- function(x) { #' vec <- c(a = 1, b = 2, c = 3) #' namedNumericToTable(vec) namedNumericToTable <- function(x) { - assertthat::assert_that(is.numeric(x) && !is.null(names(x))) + assert_that(is.numeric(x) && !is.null(names(x))) output <- as.integer(x) names(output) <- names(x) output <- as.table(output) @@ -159,8 +159,8 @@ namedNumericToTable <- function(x) { createHash <- function(keys, initVals = NULL) { if (missing(keys)) return(hash::hash()) - assertthat::assert_that(is.character(keys)) - assertthat::assert_that(is.null(initVals) || length(initVals) == 1) + assert_that(is.character(keys)) + assert_that(is.null(initVals) || length(initVals) == 1) keys <- unique(keys) numkeys <- length(keys) diff --git a/R/fileSystem.R b/R/fileSystem.R index e8a9332..4fad54f 100644 --- a/R/fileSystem.R +++ b/R/fileSystem.R @@ -22,7 +22,7 @@ #' listFiles <- function(dirPath, ...) { - assertthat::assert_that(assertthat::is.string(dirPath)) + assert_that(is.string(dirPath)) filesAndDirs <- base::do.call( list.files, diff --git a/R/ggplot.R b/R/ggplot.R index e5759a7..d9dbecf 100644 --- a/R/ggplot.R +++ b/R/ggplot.R @@ -17,7 +17,7 @@ #' getPlotDims(ggplot(mtcars) + geom_point(aes(mpg, cyl))) #' getPlotDims <- function(plt) { - assertthat::assert_that(ggplot2::is.ggplot(plt)) + assert_that(ggplot2::is.ggplot(plt)) builtPlotLayout <- ggplot2::ggplot_build(plt)$layout list( xr = builtPlotLayout$panel_scales_x[[1]]$range$range, diff --git a/R/higherOrderFunctions.R b/R/higherOrderFunctions.R index b8230a8..1444975 100644 --- a/R/higherOrderFunctions.R +++ b/R/higherOrderFunctions.R @@ -21,7 +21,7 @@ #' createMutator <- function(binaryOperator) { - assertthat::assert_that( + assert_that( is.function(binaryOperator) && length(formals(binaryOperator)) >= 2 ) diff --git a/R/math.R b/R/math.R index fe13a1d..a3a8f34 100644 --- a/R/math.R +++ b/R/math.R @@ -46,13 +46,13 @@ isBound <- function(num, lowerbound, upperbound) { } .assertNumAndBoundsAreValid <- function(num, lowerbound, upperbound) { - assertthat::assert_that(is.numeric(num)) - assertthat::assert_that(is.numeric(lowerbound)) - assertthat::assert_that( + assert_that(is.numeric(num)) + assert_that(is.numeric(lowerbound)) + assert_that( length(lowerbound) == 1 || length(lowerbound) == length(num) ) - assertthat::assert_that(is.numeric(upperbound)) - assertthat::assert_that( + assert_that(is.numeric(upperbound)) + assert_that( length(upperbound) == 1 || length(upperbound) == length(num) ) } diff --git a/R/packageDevelopment.R b/R/packageDevelopment.R index bab1423..dfdd8b5 100644 --- a/R/packageDevelopment.R +++ b/R/packageDevelopment.R @@ -27,8 +27,8 @@ #' getPkgKeywords <- function(pkg = ".", asDistribution = FALSE) { - assertthat::assert_that(assertthat::is.string(pkg)) - assertthat::assert_that(assertthat::is.flag(asDistribution)) + assert_that(is.string(pkg)) + assert_that(is.flag(asDistribution)) if (!dir.exists(pkg)) { warning("the package path does not exist") @@ -107,9 +107,9 @@ findMissingRdSections <- function( .ignore = "-package$" # are these used? ) { - assertthat::assert_that(is.character(sectionName)) - assertthat::assert_that(assertthat::is.string(pkg)) - assertthat::assert_that(is.null(ignore) || is.character(ignore)) + assert_that(is.character(sectionName)) + assert_that(is.string(pkg)) + assert_that(is.null(ignore) || is.character(ignore)) paste("\\", sectionName, "{", sep = "") %>% greplDir(file.path(pkg, "man")) %>% @@ -150,9 +150,9 @@ removeVdiffrNewSnapShots <- function( verbose = TRUE ) { - assertthat::assert_that(assertthat::is.string(pkg)) - assertthat::assert_that(assertthat::is.string(snapDir)) - assertthat::assert_that(assertthat::is.flag(verbose)) + assert_that(is.string(pkg)) + assert_that(is.string(snapDir)) + assert_that(is.flag(verbose)) if (!dir.exists(snapDir)) return(invisible()) diff --git a/R/regex.R b/R/regex.R index bca4c04..5428a1a 100644 --- a/R/regex.R +++ b/R/regex.R @@ -41,7 +41,7 @@ joinRegex <- function(...) { #' rmByName <- function(x, pattern, silent = FALSE) { - assertthat::assert_that(is.character(pattern)) + assert_that(is.character(pattern)) if (length(x) == 0) return(x) diff --git a/R/spelling.R b/R/spelling.R index efb2071..4e1a717 100644 --- a/R/spelling.R +++ b/R/spelling.R @@ -36,12 +36,12 @@ trySplitWords <- function( ) { x <- unlist(list(...), use.names = FALSE) - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) # could allow vectorize for all these... - assertthat::assert_that(assertthat::is.flag(conseq)) - assertthat::assert_that(assertthat::is.flag(strictSnake)) - assertthat::assert_that(assertthat::is.flag(uncase)) + assert_that(is.flag(conseq)) + assert_that(is.flag(strictSnake)) + assert_that(is.flag(uncase)) lapply(x, function(y) { if (isCamelCase(y) || isPascalCase(y)) { @@ -85,7 +85,7 @@ trySplitWords <- function( splitCamel <- function(x, conseq = TRUE) { - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) # could vectorize conseq if (isTRUE(conseq)) { @@ -120,7 +120,7 @@ splitPascal <- splitCamel #' splitSnake("another_example_here") #' splitSnake <- function(x) { - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) strsplit(x, "_", fixed = TRUE) } @@ -141,7 +141,7 @@ splitSnake <- function(x) { #' isCamelCase("camelcase") # returns TRUE #' isCamelCase <- function(x) { - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) grepl("^[a-z]+[A-Z]?([A-Za-z]*?)$", x) } @@ -161,7 +161,7 @@ isCamelCase <- function(x) { #' isPascalCase("pascalCase") # returns FALSE #' isPascalCase("Pascalcase") # returns TRUE isPascalCase <- function(x) { - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) grepl("^[A-Z]+[a-z]?([A-Za-z]*?)$", x) } @@ -189,8 +189,8 @@ isPascalCase <- function(x) { #' isSnakeCase <- function(x, strict = TRUE) { - assertthat::assert_that(is.character(x)) - assertthat::assert_that(assertthat::is.flag(strict)) + assert_that(is.character(x)) + assert_that(is.flag(strict)) grepl( ifelse( @@ -217,7 +217,7 @@ isSnakeCase <- function(x, strict = TRUE) { #' # Check if 'b' is a vowel #' isVowel("b") isVowel <- function(x) { - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) tolower(x) %in% c("a", "e", "i", "o", "u") } @@ -236,7 +236,7 @@ isVowel <- function(x) { #' # Check if "banana" starts with a vowel #' startsWithVowel("banana") startsWithVowel <- function(x) { - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) isVowel(getChar(x, 1)) } @@ -256,7 +256,7 @@ startsWithVowel <- function(x) { #' # Prepend an indefinite article to "banana" #' prependIndefArticle("banana") prependIndefArticle <- function(x) { - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) paste0("a", ifelse(startsWithVowel(x), "n", ""), " ", x) } @@ -277,7 +277,7 @@ pia <- prependIndefArticle #' # Remove spaces from "hello world" #' stripSpaces("hello world") stripSpaces <- function(x) { - assertthat::assert_that(is.character(x)) + assert_that(is.character(x)) gsub(" ", "", x) } @@ -299,9 +299,9 @@ stripSpaces <- function(x) { #' closestWord("hello", c("hallo", "hullo", "hey")) closestWord <- function(s, strset, distFunc = utils::adist) { - assertthat::assert_that(is.character(s)) - assertthat::assert_that(is.character(strset)) - assertthat::assert_that( + assert_that(is.character(s)) + assert_that(is.character(strset)) + assert_that( is.function(distFunc) && (length(formals(distFunc)) >= 2) ) diff --git a/R/testing.R b/R/testing.R index 4a01f0d..ccb90f8 100644 --- a/R/testing.R +++ b/R/testing.R @@ -39,8 +39,8 @@ initTestthat <- function( ignore = NULL ) { - assertthat::assert_that(is.character(rDir) && is.character(testDir)) - assertthat::assert_that(is.null(ignore) || is.character(ignore)) + assert_that(is.character(rDir) && is.character(testDir)) + assert_that(is.null(ignore) || is.character(ignore)) if (!dir.exists(testDir)) usethis::use_testthat() ignoreRegex <- encloseBr(paste(append(.ignore, ignore), collapse = ")|(")) diff --git a/R/validation.R b/R/validation.R index 480db16..c497b06 100644 --- a/R/validation.R +++ b/R/validation.R @@ -5,7 +5,7 @@ #' function is intended to slightly simplify cases where a long list of #' complex and convoluted predetermined checks are needed. For simpler cases #' like type checking, it is recommended to use [stopifnot()] or -#' [assertthat::assert_that()]. +#' [assert_that()]. #' #' @param obj The object to validate. #' @param checks A single function or list of functions, each taking the object diff --git a/R/wrangling.R b/R/wrangling.R index c29d34c..18d91f6 100644 --- a/R/wrangling.R +++ b/R/wrangling.R @@ -151,7 +151,7 @@ setRownames <- function(object, newRownames) { #' x %setNames% c("D", "E", "F") #' setNames <- function(object, newNames) { - assertthat::assert_that( + assert_that( length(newNames) == 1 || length(newNames) == length(object) ) names(object) <- if (length(newNames) == length(object)) { @@ -212,8 +212,8 @@ fixColnames <- function( unique = FALSE ) { - assertthat::assert_that(assertthat::is.string(invalidRegex)) - assertthat::assert_that(assertthat::is.string(spacing)) + assert_that(is.string(invalidRegex)) + assert_that(is.string(spacing)) subMap <- append(subMap, .subMap) diff --git a/man/validateObject.Rd b/man/validateObject.Rd index 05b2ce0..721655c 100644 --- a/man/validateObject.Rd +++ b/man/validateObject.Rd @@ -28,7 +28,7 @@ fails, an error handler is called and a default value is returned. This function is intended to slightly simplify cases where a long list of complex and convoluted predetermined checks are needed. For simpler cases like type checking, it is recommended to use \code{\link[=stopifnot]{stopifnot()}} or -\code{\link[assertthat:assert_that]{assertthat::assert_that()}}. +\code{\link[=assert_that]{assert_that()}}. } \examples{ # Define some checks