From 4c2de53d614c81ec8990b6186d2c9ed89f77166e Mon Sep 17 00:00:00 2001 From: Michel Lang Date: Fri, 19 Jul 2024 21:20:30 +0200 Subject: [PATCH] style: fix some style issues --- R/assert.R | 11 +++++------ R/checkCharacter.R | 2 +- R/checkClass.R | 2 +- R/checkDataFrame.R | 2 +- R/checkFactor.R | 2 +- R/checkFileExists.R | 7 ++++--- R/checkList.R | 2 +- R/checkMultiClass.R | 6 ++++-- R/checkNames.R | 3 ++- R/checkString.R | 2 +- R/helper.R | 6 +++--- R/zzz.R | 2 +- 12 files changed, 25 insertions(+), 22 deletions(-) diff --git a/R/assert.R b/R/assert.R index cca1afef..73d468e8 100644 --- a/R/assert.R +++ b/R/assert.R @@ -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 @@ -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) @@ -61,7 +60,7 @@ 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 @@ -69,8 +68,8 @@ assert = function(..., combine = "or", .var.name = NULL, add = NULL) { # 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) { diff --git a/R/checkCharacter.R b/R/checkCharacter.R index db4c85c4..5afef2e4 100644 --- a/R/checkCharacter.R +++ b/R/checkCharacter.R @@ -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) { diff --git a/R/checkClass.R b/R/checkClass.R index 41d5b69c..4da26f7d 100644 --- a/R/checkClass.R +++ b/R/checkClass.R @@ -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)) diff --git a/R/checkDataFrame.R b/R/checkDataFrame.R index 50d88333..1ebe968c 100644 --- a/R/checkDataFrame.R +++ b/R/checkDataFrame.R @@ -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 diff --git a/R/checkFactor.R b/R/checkFactor.R index cf4320b4..5e7e2243 100644 --- a/R/checkFactor.R +++ b/R/checkFactor.R @@ -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") diff --git a/R/checkFileExists.R b/R/checkFileExists.R index aae002e8..59428ee6 100644 --- a/R/checkFileExists.R +++ b/R/checkFileExists.R @@ -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) } diff --git a/R/checkList.R b/R/checkList.R index ecbc1b69..9e0cdb53 100644 --- a/R/checkList.R +++ b/R/checkList.R @@ -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)) { diff --git a/R/checkMultiClass.R b/R/checkMultiClass.R index e6eec90a..f2609b93 100644 --- a/R/checkMultiClass.R +++ b/R/checkMultiClass.R @@ -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) } diff --git a/R/checkNames.R b/R/checkNames.R index b7b41d73..f5942bbe 100644 --- a/R/checkNames.R +++ b/R/checkNames.R @@ -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}. diff --git a/R/checkString.R b/R/checkString.R index 54f55559..1a6c3cfa 100644 --- a/R/checkString.R +++ b/R/checkString.R @@ -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 diff --git a/R/helper.R b/R/helper.R index 85fee2e0..ae19e584 100644 --- a/R/helper.R +++ b/R/helper.R @@ -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)]) )) } diff --git a/R/zzz.R b/R/zzz.R index ef35cb1d..d4344469 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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 }