Skip to content

Commit

Permalink
import assert_that, is.flag, is.stringh
Browse files Browse the repository at this point in the history
  • Loading branch information
Qile0317 committed Oct 2, 2024
1 parent 36f6a86 commit 290f834
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 53 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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,"!!")
Expand Down
1 change: 1 addition & 0 deletions R/FastUtils-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions R/character.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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, "(", ")")
}

Expand All @@ -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)
)

Expand Down
6 changes: 3 additions & 3 deletions R/dataInitialization.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/fileSystem.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/ggplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/higherOrderFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#'
createMutator <- function(binaryOperator) {

assertthat::assert_that(
assert_that(
is.function(binaryOperator) && length(formals(binaryOperator)) >= 2
)

Expand Down
10 changes: 5 additions & 5 deletions R/math.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
Expand Down
16 changes: 8 additions & 8 deletions R/packageDevelopment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")) %>%
Expand Down Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion R/regex.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
34 changes: 17 additions & 17 deletions R/spelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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(
Expand All @@ -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")
}

Expand All @@ -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))
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
)

Expand Down
4 changes: 2 additions & 2 deletions R/testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ")|("))
Expand Down
2 changes: 1 addition & 1 deletion R/validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/wrangling.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion man/validateObject.Rd

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

0 comments on commit 290f834

Please sign in to comment.