Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Reorganize documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Nov 6, 2024
1 parent ea46527 commit 818555c
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 106 deletions.
47 changes: 27 additions & 20 deletions R/assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ src="https://tesselle.r-universe.dev/badges/arkhe"
alt="r-universe" /></a>
<a href="https://cran.r-project.org/package=arkhe"
class="pkgdown-release"><img
src="http://www.r-pkg.org/badges/version/arkhe"
src="https://www.r-pkg.org/badges/version/arkhe"
alt="CRAN Version" /></a>
<a href="https://cran.r-project.org/web/checks/check_results_arkhe.html"
class="pkgdown-release"><img
src="https://badges.cranchecks.info/worst/arkhe.svg"
alt="CRAN checks" /></a>
<a href="https://cran.r-project.org/package=arkhe"
class="pkgdown-release"><img
src="http://cranlogs.r-pkg.org/badges/arkhe" alt="CRAN Downloads" /></a>
src="https://cranlogs.r-pkg.org/badges/arkhe"
alt="CRAN Downloads" /></a>

[![Project Status: Active – The project has reached a stable, usable
state and is being actively
Expand All @@ -48,7 +49,7 @@ To cite arkhe in publications use:
Frerebeau N (2024). *arkhe: Tools for Cleaning Rectangular Data*.
Université Bordeaux Montaigne, Pessac, France.
<doi:10.5281/zenodo.3526659> <https://doi.org/10.5281/zenodo.3526659>, R
package version 1.7.0, <https://packages.tesselle.org/arkhe/>.
package version 1.7.0.9000, <https://packages.tesselle.org/arkhe/>.

This package is a part of the tesselle project
<https://www.tesselle.org>.
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions man/assert_constant.Rd

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

24 changes: 7 additions & 17 deletions man/assert_data.Rd → man/assert_infinite.Rd

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

9 changes: 5 additions & 4 deletions man/assert_length.Rd

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

9 changes: 5 additions & 4 deletions man/assert_lower.Rd

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

Loading

0 comments on commit 818555c

Please sign in to comment.