Skip to content

Commit

Permalink
style: fix some style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mllg committed Jul 19, 2024
1 parent e40ee0c commit 4c2de53
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 22 deletions.
11 changes: 5 additions & 6 deletions R/assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#' \dQuote{or} or \dQuote{and} to combine the check functions with an OR
#' or AND, respectively.
#' @template assert
#' @return Throws an error (or pushes the error message to an
#' \code{\link{AssertCollection}} if \code{add} is not \code{NULL})
#' @return Throws an error (or pushes the error message to an
#' \code{\link{AssertCollection}} if \code{add} is not \code{NULL})
#' if the checks fail and invisibly returns \code{TRUE} otherwise.
#' @export
#' @examples
Expand All @@ -25,7 +25,6 @@
#' collection <- makeAssertCollection()
#' assert(checkChoice(x, c("a", "b")), checkDataFrame(x), add = collection)
#' collection$getMessages()
#'
assert = function(..., combine = "or", .var.name = NULL, add = NULL) {
assertChoice(combine, c("or", "and"))
assertClass(add, "AssertCollection", .var.name = "add", null.ok = TRUE)
Expand Down Expand Up @@ -61,16 +60,16 @@ assert = function(..., combine = "or", .var.name = NULL, add = NULL) {
}

# Error handling in assert()
#
#
# Internal helper function to handle errors in assert().
# @param res [character(1)}]\cr
# error message
# @param v_name [\code{character}]\cr
# Name(s) of the variable(s) whose assertion failed.
# @param collection [\code{AssertCollection} | \code{NULL}]\cr
# See AssertCollection.
# @return mstopOrPush() throws an exception by calling
# mstop() if 'collection' is NULL, or
# @return mstopOrPush() throws an exception by calling
# mstop() if 'collection' is NULL, or
# pushes the error message to the collection otherwise.
# @keywords internal
mstopOrPush = function(res, v_name, collection = NULL) {
Expand Down
2 changes: 1 addition & 1 deletion R/checkCharacter.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#' testCharacter("example", pattern = "xa")
checkCharacter = function(x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE) {
.Call(c_check_character, x, n.chars, min.chars, max.chars, any.missing, all.missing, len, min.len, max.len, unique, sorted, names, typed.missing, null.ok) %and%
checkCharacterPattern(x, pattern, fixed, ignore.case)
checkCharacterPattern(x, pattern, fixed, ignore.case)
}

checkCharacterPattern = function(x, pattern = NULL, fixed = NULL, ignore.case = FALSE) {
Expand Down
2 changes: 1 addition & 1 deletion R/checkClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ checkClass = function(x, classes, ordered = FALSE, null.ok = FALSE) {
if (length(w) > 0L) {
cl = class(x)
return(sprintf("Must inherit from class '%s', but has class%s '%s'",
classes[w], if (length(cl) > 1L) "es" else "", paste0(cl, collapse = "','")))
classes[w], if (length(cl) > 1L) "es" else "", paste0(cl, collapse = "','")))
}
if (ordered) {
w = wf(ord != seq_along(ord))
Expand Down
2 changes: 1 addition & 1 deletion R/checkDataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' testDataFrame(iris, types = c("numeric", "factor"), min.rows = 1, col.names = "named")
checkDataFrame = function(x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE) {
.Call(c_check_dataframe, x, any.missing, all.missing, min.rows, max.rows, min.cols, max.cols, nrows, ncols, row.names, col.names, null.ok) %and%
checkListTypes(x, types)
checkListTypes(x, types)
}

#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/checkFactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ checkFactor = function(x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, a
checkFactorLevels(x, levels, ordered, empty.levels.ok, n.levels, min.levels, max.levels)
}

checkFactorLevels = function(x , levels = NULL, ordered = NA, empty.levels.ok = TRUE, n.levels = NULL, min.levels = NULL, max.levels = NULL) {
checkFactorLevels = function(x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, n.levels = NULL, min.levels = NULL, max.levels = NULL) {
if (!is.null(x)) {
if (!is.null(levels)) {
qassert(levels, "S")
Expand Down
7 changes: 4 additions & 3 deletions R/checkFileExists.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ checkFileExtension = function(x, extension = NULL) {
qassert(extension, "S+")
ii = Reduce(`|`, lapply(tolower(extension), endsWith, x = tolower(x)))
if (!all(ii))
return(sprintf("File extension must be in {'%s'} (case insensitive), but file name is '%s'",
paste0(extension, collapse = "','"),
x[wf(!ii)]))
return(sprintf(
"File extension must be in {'%s'} (case insensitive), but file name is '%s'",
paste0(extension, collapse = "','"), x[wf(!ii)]
))
}
return(TRUE)
}
Expand Down
2 changes: 1 addition & 1 deletion R/checkList.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#' testList(list(NA, NA_real_), unique = TRUE)
checkList = function(x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE) {
.Call(c_check_list, x, any.missing, all.missing, len, min.len, max.len, unique, names, null.ok) %and%
checkListTypes(x, types)
checkListTypes(x, types)
}

checkListTypes = function(x, types = character(0L)) {
Expand Down
6 changes: 4 additions & 2 deletions R/checkMultiClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ checkMultiClass = function(x, classes, null.ok = FALSE) {
return(TRUE)
if (!inherits(x, classes)) {
cl = class(x)
return(sprintf("Must inherit from class '%s', but has class%s '%s'",
paste0(classes, collapse = "'/'"), if (length(cl) > 1L) "es" else "", paste0(cl, collapse = "','")))
return(sprintf(
"Must inherit from class '%s', but has class%s '%s'",
paste0(classes, collapse = "'/'"), if (length(cl) > 1L) "es" else "", paste0(cl, collapse = "','")
))
}
return(TRUE)
}
Expand Down
3 changes: 2 additions & 1 deletion R/checkNames.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#' \item{unnamed:}{Checks \code{x} to be \code{NULL}.}
#' \item{named:}{Checks \code{x} for regular names which excludes names to be \code{NA} or empty (\code{""}).}
#' \item{unique:}{Performs checks like with \dQuote{named} and additionally tests for non-duplicated names.}
#' \item{strict:}{Performs checks like with \dQuote{unique} and additionally fails for names with UTF-8 characters and names which do not comply to R's variable name restrictions. As regular expression, this is \dQuote{^[.]*[a-zA-Z]+[a-zA-Z0-9._]*$}.}
#' \item{strict:}{Performs checks like with \dQuote{unique} and additionally fails for names with UTF-8 characters and names which do not comply to R's variable name restrictions.
#' As regular expression, this is \dQuote{^[.]*[a-zA-Z]+[a-zA-Z0-9._]*$}.}
#' \item{ids:}{Same as \dQuote{strict}, but does not enforce uniqueness.}
#' }
#' Note that for zero-length \code{x}, all these name checks evaluate to \code{TRUE}.
Expand Down
2 changes: 1 addition & 1 deletion R/checkString.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' testString(letters)
checkString = function(x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE) {
.Call(c_check_string, x, na.ok, n.chars, min.chars, max.chars, null.ok) %and%
checkCharacterPattern(x, pattern, fixed, ignore.case)
checkCharacterPattern(x, pattern, fixed, ignore.case)
}

#' @export
Expand Down
6 changes: 3 additions & 3 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ check_subset_internal = function(x, choices, match, what = NULL) {
check_set_equal_internal = function(x, y, match, what = NULL) {
if ((!isSameType(x, y) && !allMissing(x))) {
return(set_msg("Must be setequal to %s, but has different type",
what, set_collapse(y)))
what, set_collapse(y)))
}

ii = match(x, y)
if (anyMissing(ii)) {
return(set_msg("must be a permutation of set %s, but has extra elements %s",
what, set_collapse(y), set_collapse(x[is.na(ii)])
what, set_collapse(y), set_collapse(x[is.na(ii)])
))
}

ii = match(y, x)
if (anyMissing(ii)) {
return(set_msg("must be a set equal to %s, but is missing elements %s",
what, set_collapse(y), set_collapse(y[is.na(ii)])
what, set_collapse(y), set_collapse(y[is.na(ii)])
))
}

Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ register_tinytest = function() {
setHook(packageEvent("tinytest", "onLoad"), function(...) register_tinytest(), action = "append")
}

.onUnload = function (libpath) {
.onUnload = function(libpath) {
library.dynam.unload("checkmate", libpath) # nocov
}

0 comments on commit 4c2de53

Please sign in to comment.