diff --git a/R/assert.R b/R/assert.R index 2d65d27..1d01230 100644 --- a/R/assert.R +++ b/R/assert.R @@ -33,7 +33,7 @@ validate <- function(expr) { #' #' `needs()` is an alias for `assert_package()`. #' @return Invisibly returns `NULL`. -#' @family validation methods +#' @family checking methods #' @author N. Frerebeau #' @export assert_package <- function(x, ask = TRUE) { @@ -80,7 +80,7 @@ needs <- assert_package #' @return #' Throws an error, if any, and returns `x` invisibly otherwise. #' @author N. Frerebeau -#' @family validation methods +#' @family checking methods #' @export assert_length <- function(x, expected, empty = FALSE) { arg <- deparse(substitute(x)) @@ -150,7 +150,7 @@ assert_dimensions <- function(x, expected) { #' @return #' Throws an error, if any, and returns `x` invisibly otherwise. #' @author N. Frerebeau -#' @family validation methods +#' @family checking methods #' @export assert_names <- function(x, expected = NULL) { arg <- deparse(substitute(x)) @@ -199,22 +199,15 @@ assert_colnames <- function(x, expected = NULL) { } # NA/NaN/Inf/duplicates ======================================================== -#' Check Data +#' Check Missing Values #' -#' * `assert_missing()` and `assert_infinite()` check if an object contains any -#' missing (`NA`, `NaN`) or infinite (`Inf`) value. -#' * `assert_unique()` checks if an object contains duplicated elements. +#' Checks if an object contains any missing (`NA`, `NaN`) values. #' @param x An object to be checked. #' @return #' Throws an error, if any, and returns `x` invisibly otherwise. #' @author N. Frerebeau -#' @family validation methods -#' @name assert_data -#' @rdname assert_data -NULL - +#' @family checking methods #' @export -#' @rdname assert_data assert_missing <- function(x) { arg <- deparse(substitute(x)) n <- sum(is.na(x)) @@ -226,8 +219,15 @@ assert_missing <- function(x) { invisible(x) } +#' Check Infinite Values +#' +#' Checks if an object contains any infinite (`Inf`) values. +#' @param x An object to be checked. +#' @return +#' Throws an error, if any, and returns `x` invisibly otherwise. +#' @author N. Frerebeau +#' @family checking methods #' @export -#' @rdname assert_data assert_infinite <- function(x) { arg <- deparse(substitute(x)) n <- sum(is.infinite(x)) @@ -239,8 +239,15 @@ assert_infinite <- function(x) { invisible(x) } +#' Check Duplicates +#' +#' Checks if an object contains duplicated elements. +#' @param x An object to be checked. +#' @return +#' Throws an error, if any, and returns `x` invisibly otherwise. +#' @author N. Frerebeau +#' @family checking methods #' @export -#' @rdname assert_data assert_unique <- function(x) { arg <- deparse(substitute(x)) if (has_duplicates(x)) { @@ -333,7 +340,7 @@ assert_function <- function(x) { #' @return #' Throws an error, if any, and returns `x` invisibly otherwise. #' @author N. Frerebeau -#' @family validation methods +#' @family checking methods #' @name assert_numeric #' @rdname assert_numeric NULL @@ -404,7 +411,7 @@ assert_even <- function(x, na.rm = FALSE, ...) { #' @return #' Throws an error, if any, and returns `x` invisibly otherwise. #' @author N. Frerebeau -#' @family validation methods +#' @family checking methods #' @export assert_constant <- function(x, ...) { arg <- deparse(substitute(x)) @@ -444,7 +451,7 @@ assert_increasing <- function(x, ...) { #' @return #' Throws an error, if any, and returns `x` invisibly otherwise. #' @author N. Frerebeau -#' @family validation methods +#' @family checking methods #' @export assert_lower <- function(x, y, ...) { arg_x <- deparse(substitute(x)) @@ -474,7 +481,7 @@ assert_greater <- function(x, y, ...) { #' @param x A [`matrix`] to be checked. #' @return Throw an error, if any, and returns `x` invisibly otherwise. #' @author N. Frerebeau -#' @family validation methods +#' @family checking methods #' @export assert_square <- function(x) { arg <- deparse(substitute(x)) @@ -503,7 +510,7 @@ assert_symmetric <- function(x) { # @param expected An appropriate expected value. # @return Throw an error, if any. # @author N. Frerebeau -# @family validation methods +# @family checking methods # @keywords internal # @export # assert_dag <- function(x) { diff --git a/README.Rmd b/README.Rmd index a045648..f49e694 100644 --- a/README.Rmd +++ b/README.Rmd @@ -23,9 +23,9 @@ Sys.setlocale("LC_MESSAGES", 'en_GB.UTF-8') # Force locale [![Dependencies](https://tinyverse.netlify.app/badge/arkhe)](https://cran.r-project.org/package=arkhe) [![r-universe](https://tesselle.r-universe.dev/badges/arkhe)](https://tesselle.r-universe.dev/arkhe){.pkgdown-devel} -[![CRAN Version](http://www.r-pkg.org/badges/version/arkhe)](https://cran.r-project.org/package=arkhe){.pkgdown-release} +[![CRAN Version](https://www.r-pkg.org/badges/version/arkhe)](https://cran.r-project.org/package=arkhe){.pkgdown-release} [![CRAN checks](https://badges.cranchecks.info/worst/arkhe.svg)](https://cran.r-project.org/web/checks/check_results_arkhe.html){.pkgdown-release} -[![CRAN Downloads](http://cranlogs.r-pkg.org/badges/arkhe)](https://cran.r-project.org/package=arkhe){.pkgdown-release} +[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/arkhe)](https://cran.r-project.org/package=arkhe){.pkgdown-release} [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) @@ -92,4 +92,5 @@ replace_NA(X, value = 0) ``` ## Contributing + Please note that the **arkhe** project is released with a [Contributor Code of Conduct](https://www.tesselle.org/conduct.html). By contributing to this project, you agree to abide by its terms. diff --git a/README.md b/README.md index 3bf9e3f..94ddd27 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ src="https://tesselle.r-universe.dev/badges/arkhe" alt="r-universe" /> CRAN Version CRAN checks CRAN Downloads +src="https://cranlogs.r-pkg.org/badges/arkhe" +alt="CRAN Downloads" /> [![Project Status: Active – The project has reached a stable, usable state and is being actively @@ -48,7 +49,7 @@ To cite arkhe in publications use: Frerebeau N (2024). *arkhe: Tools for Cleaning Rectangular Data*. Université Bordeaux Montaigne, Pessac, France. , R -package version 1.7.0, . +package version 1.7.0.9000, . This package is a part of the tesselle project . @@ -83,48 +84,48 @@ k <- sample(1:25, 3, FALSE) X[k] <- NA X #> [,1] [,2] [,3] [,4] [,5] -#> [1,] 7 8 9 1 NA -#> [2,] 8 9 7 2 3 -#> [3,] 8 NA 2 10 2 -#> [4,] 4 7 7 5 3 -#> [5,] 4 7 NA 6 1 +#> [1,] 1 7 10 2 6 +#> [2,] 9 7 7 3 5 +#> [3,] 6 NA 8 10 5 +#> [4,] 1 10 8 2 NA +#> [5,] NA 1 4 9 8 ## Count missing values in rows count(X, f = is.na, margin = 1) -#> [1] 1 0 1 0 1 +#> [1] 0 0 1 1 1 ## Count non-missing values in columns count(X, f = is.na, margin = 2, negate = TRUE) -#> [1] 5 4 4 5 4 +#> [1] 4 4 5 5 4 ## Find row with NA detect(X, f = is.na, margin = 1) -#> [1] TRUE FALSE TRUE FALSE TRUE +#> [1] FALSE FALSE TRUE TRUE TRUE ## Find column without any NA detect(X, f = is.na, margin = 2, negate = TRUE, all = TRUE) -#> [1] TRUE FALSE FALSE TRUE FALSE +#> [1] FALSE FALSE TRUE TRUE FALSE ## Remove row with any NA discard(X, f = is.na, margin = 1, all = FALSE) #> [,1] [,2] [,3] [,4] [,5] -#> [1,] 8 9 7 2 3 -#> [2,] 4 7 7 5 3 +#> [1,] 1 7 10 2 6 +#> [2,] 9 7 7 3 5 ## Remove column with any NA discard(X, f = is.na, margin = 2, all = FALSE) #> [,1] [,2] -#> [1,] 7 1 -#> [2,] 8 2 +#> [1,] 10 2 +#> [2,] 7 3 #> [3,] 8 10 -#> [4,] 4 5 -#> [5,] 4 6 +#> [4,] 8 2 +#> [5,] 4 9 ## Replace NA with zeros replace_NA(X, value = 0) #> [,1] [,2] [,3] [,4] [,5] -#> [1,] 7 8 9 1 0 -#> [2,] 8 9 7 2 3 -#> [3,] 8 0 2 10 2 -#> [4,] 4 7 7 5 3 -#> [5,] 4 7 0 6 1 +#> [1,] 1 7 10 2 6 +#> [2,] 9 7 7 3 5 +#> [3,] 6 0 8 10 5 +#> [4,] 1 10 8 2 0 +#> [5,] 0 1 4 9 8 ``` ## Contributing diff --git a/man/assert_constant.Rd b/man/assert_constant.Rd index 9b2a862..d3f3500 100644 --- a/man/assert_constant.Rd +++ b/man/assert_constant.Rd @@ -24,18 +24,19 @@ Throws an error, if any, and returns \code{x} invisibly otherwise. Check Numeric Trend } \seealso{ -Other validation methods: -\code{\link{assert_data}}, +Other checking methods: +\code{\link{assert_infinite}()}, \code{\link{assert_length}()}, \code{\link{assert_lower}()}, +\code{\link{assert_missing}()}, \code{\link{assert_names}()}, \code{\link{assert_numeric}}, \code{\link{assert_package}()}, \code{\link{assert_square}()}, \code{\link{assert_type}()}, -\code{\link{validate}()} +\code{\link{assert_unique}()} } \author{ N. Frerebeau } -\concept{validation methods} +\concept{checking methods} diff --git a/man/assert_data.Rd b/man/assert_infinite.Rd similarity index 54% rename from man/assert_data.Rd rename to man/assert_infinite.Rd index 90213e6..f226c0f 100644 --- a/man/assert_data.Rd +++ b/man/assert_infinite.Rd @@ -1,17 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/assert.R -\name{assert_data} -\alias{assert_data} -\alias{assert_missing} +\name{assert_infinite} \alias{assert_infinite} -\alias{assert_unique} -\title{Check Data} +\title{Check Infinite Values} \usage{ -assert_missing(x) - assert_infinite(x) - -assert_unique(x) } \arguments{ \item{x}{An object to be checked.} @@ -20,25 +13,22 @@ assert_unique(x) Throws an error, if any, and returns \code{x} invisibly otherwise. } \description{ -\itemize{ -\item \code{assert_missing()} and \code{assert_infinite()} check if an object contains any -missing (\code{NA}, \code{NaN}) or infinite (\code{Inf}) value. -\item \code{assert_unique()} checks if an object contains duplicated elements. -} +Checks if an object contains any infinite (\code{Inf}) values. } \seealso{ -Other validation methods: +Other checking methods: \code{\link{assert_constant}()}, \code{\link{assert_length}()}, \code{\link{assert_lower}()}, +\code{\link{assert_missing}()}, \code{\link{assert_names}()}, \code{\link{assert_numeric}}, \code{\link{assert_package}()}, \code{\link{assert_square}()}, \code{\link{assert_type}()}, -\code{\link{validate}()} +\code{\link{assert_unique}()} } \author{ N. Frerebeau } -\concept{validation methods} +\concept{checking methods} diff --git a/man/assert_length.Rd b/man/assert_length.Rd index 4b26b0d..3e8d46f 100644 --- a/man/assert_length.Rd +++ b/man/assert_length.Rd @@ -32,18 +32,19 @@ Throws an error, if any, and returns \code{x} invisibly otherwise. Check Object Length/Dimensions } \seealso{ -Other validation methods: +Other checking methods: \code{\link{assert_constant}()}, -\code{\link{assert_data}}, +\code{\link{assert_infinite}()}, \code{\link{assert_lower}()}, +\code{\link{assert_missing}()}, \code{\link{assert_names}()}, \code{\link{assert_numeric}}, \code{\link{assert_package}()}, \code{\link{assert_square}()}, \code{\link{assert_type}()}, -\code{\link{validate}()} +\code{\link{assert_unique}()} } \author{ N. Frerebeau } -\concept{validation methods} +\concept{checking methods} diff --git a/man/assert_lower.Rd b/man/assert_lower.Rd index bddbf43..681c563 100644 --- a/man/assert_lower.Rd +++ b/man/assert_lower.Rd @@ -21,18 +21,19 @@ Throws an error, if any, and returns \code{x} invisibly otherwise. Check Numeric Relations } \seealso{ -Other validation methods: +Other checking methods: \code{\link{assert_constant}()}, -\code{\link{assert_data}}, +\code{\link{assert_infinite}()}, \code{\link{assert_length}()}, +\code{\link{assert_missing}()}, \code{\link{assert_names}()}, \code{\link{assert_numeric}}, \code{\link{assert_package}()}, \code{\link{assert_square}()}, \code{\link{assert_type}()}, -\code{\link{validate}()} +\code{\link{assert_unique}()} } \author{ N. Frerebeau } -\concept{validation methods} +\concept{checking methods} diff --git a/man/assert_missing.Rd b/man/assert_missing.Rd new file mode 100644 index 0000000..acbc47f --- /dev/null +++ b/man/assert_missing.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/assert.R +\name{assert_missing} +\alias{assert_missing} +\title{Check Missing Values} +\usage{ +assert_missing(x) +} +\arguments{ +\item{x}{An object to be checked.} +} +\value{ +Throws an error, if any, and returns \code{x} invisibly otherwise. +} +\description{ +Checks if an object contains any missing (\code{NA}, \code{NaN}) values. +} +\seealso{ +Other checking methods: +\code{\link{assert_constant}()}, +\code{\link{assert_infinite}()}, +\code{\link{assert_length}()}, +\code{\link{assert_lower}()}, +\code{\link{assert_names}()}, +\code{\link{assert_numeric}}, +\code{\link{assert_package}()}, +\code{\link{assert_square}()}, +\code{\link{assert_type}()}, +\code{\link{assert_unique}()} +} +\author{ +N. Frerebeau +} +\concept{checking methods} diff --git a/man/assert_names.Rd b/man/assert_names.Rd index a8238b3..d1e7c3b 100644 --- a/man/assert_names.Rd +++ b/man/assert_names.Rd @@ -24,18 +24,19 @@ Throws an error, if any, and returns \code{x} invisibly otherwise. Check Object Names } \seealso{ -Other validation methods: +Other checking methods: \code{\link{assert_constant}()}, -\code{\link{assert_data}}, +\code{\link{assert_infinite}()}, \code{\link{assert_length}()}, \code{\link{assert_lower}()}, +\code{\link{assert_missing}()}, \code{\link{assert_numeric}}, \code{\link{assert_package}()}, \code{\link{assert_square}()}, \code{\link{assert_type}()}, -\code{\link{validate}()} +\code{\link{assert_unique}()} } \author{ N. Frerebeau } -\concept{validation methods} +\concept{checking methods} diff --git a/man/assert_numeric.Rd b/man/assert_numeric.Rd index 37a4528..a46dda6 100644 --- a/man/assert_numeric.Rd +++ b/man/assert_numeric.Rd @@ -37,18 +37,19 @@ Throws an error, if any, and returns \code{x} invisibly otherwise. Check Numeric Values } \seealso{ -Other validation methods: +Other checking methods: \code{\link{assert_constant}()}, -\code{\link{assert_data}}, +\code{\link{assert_infinite}()}, \code{\link{assert_length}()}, \code{\link{assert_lower}()}, +\code{\link{assert_missing}()}, \code{\link{assert_names}()}, \code{\link{assert_package}()}, \code{\link{assert_square}()}, \code{\link{assert_type}()}, -\code{\link{validate}()} +\code{\link{assert_unique}()} } \author{ N. Frerebeau } -\concept{validation methods} +\concept{checking methods} diff --git a/man/assert_package.Rd b/man/assert_package.Rd index 0b20d48..173adcf 100644 --- a/man/assert_package.Rd +++ b/man/assert_package.Rd @@ -31,18 +31,19 @@ the user will be asked to install the packages. \code{needs()} is an alias for \code{assert_package()}. } \seealso{ -Other validation methods: +Other checking methods: \code{\link{assert_constant}()}, -\code{\link{assert_data}}, +\code{\link{assert_infinite}()}, \code{\link{assert_length}()}, \code{\link{assert_lower}()}, +\code{\link{assert_missing}()}, \code{\link{assert_names}()}, \code{\link{assert_numeric}}, \code{\link{assert_square}()}, \code{\link{assert_type}()}, -\code{\link{validate}()} +\code{\link{assert_unique}()} } \author{ N. Frerebeau } -\concept{validation methods} +\concept{checking methods} diff --git a/man/assert_square.Rd b/man/assert_square.Rd index ace3be2..d29bc2d 100644 --- a/man/assert_square.Rd +++ b/man/assert_square.Rd @@ -19,18 +19,19 @@ Throw an error, if any, and returns \code{x} invisibly otherwise. Check Matrix } \seealso{ -Other validation methods: +Other checking methods: \code{\link{assert_constant}()}, -\code{\link{assert_data}}, +\code{\link{assert_infinite}()}, \code{\link{assert_length}()}, \code{\link{assert_lower}()}, +\code{\link{assert_missing}()}, \code{\link{assert_names}()}, \code{\link{assert_numeric}}, \code{\link{assert_package}()}, \code{\link{assert_type}()}, -\code{\link{validate}()} +\code{\link{assert_unique}()} } \author{ N. Frerebeau } -\concept{validation methods} +\concept{checking methods} diff --git a/man/assert_type.Rd b/man/assert_type.Rd index bcbcc2a..09ac3e6 100644 --- a/man/assert_type.Rd +++ b/man/assert_type.Rd @@ -31,18 +31,19 @@ Throws an error, if any, and returns \code{x} invisibly otherwise. Check Data Types } \seealso{ -Other validation methods: +Other checking methods: \code{\link{assert_constant}()}, -\code{\link{assert_data}}, +\code{\link{assert_infinite}()}, \code{\link{assert_length}()}, \code{\link{assert_lower}()}, +\code{\link{assert_missing}()}, \code{\link{assert_names}()}, \code{\link{assert_numeric}}, \code{\link{assert_package}()}, \code{\link{assert_square}()}, -\code{\link{validate}()} +\code{\link{assert_unique}()} } \author{ N. Frerebeau } -\concept{validation methods} +\concept{checking methods} diff --git a/man/assert_unique.Rd b/man/assert_unique.Rd new file mode 100644 index 0000000..67cad02 --- /dev/null +++ b/man/assert_unique.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/assert.R +\name{assert_unique} +\alias{assert_unique} +\title{Check Duplicates} +\usage{ +assert_unique(x) +} +\arguments{ +\item{x}{An object to be checked.} +} +\value{ +Throws an error, if any, and returns \code{x} invisibly otherwise. +} +\description{ +Checks if an object contains duplicated elements. +} +\seealso{ +Other checking methods: +\code{\link{assert_constant}()}, +\code{\link{assert_infinite}()}, +\code{\link{assert_length}()}, +\code{\link{assert_lower}()}, +\code{\link{assert_missing}()}, +\code{\link{assert_names}()}, +\code{\link{assert_numeric}}, +\code{\link{assert_package}()}, +\code{\link{assert_square}()}, +\code{\link{assert_type}()} +} +\author{ +N. Frerebeau +} +\concept{checking methods} diff --git a/man/validate.Rd b/man/validate.Rd index 350848a..b9bae3d 100644 --- a/man/validate.Rd +++ b/man/validate.Rd @@ -15,18 +15,6 @@ Returns \code{NULL} on success, otherwise returns the error as a string. \description{ Validate a Condition } -\seealso{ -Other validation methods: -\code{\link{assert_constant}()}, -\code{\link{assert_data}}, -\code{\link{assert_length}()}, -\code{\link{assert_lower}()}, -\code{\link{assert_names}()}, -\code{\link{assert_numeric}}, -\code{\link{assert_package}()}, -\code{\link{assert_square}()}, -\code{\link{assert_type}()} -} \author{ N. Frerebeau }