diff --git a/LICENSE.html b/LICENSE.html index 51e050a..704ddc6 100644 --- a/LICENSE.html +++ b/LICENSE.html @@ -46,6 +46,7 @@
Copyright (c) 2024 Daniel Vartanian
@@ -53,6 +54,40 @@The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This package incorporates C code from the checkmate
R package, linked via the LinkingTo
field in the DESCRIPTION
file. The code is released under the 3-Clause BSD License, as indicated in the license notice below.
Additionally, it is worth noting that the MIT License is compatible with the BSD-3-Clause License.
+Copyright (c) 2023, Michel Lang
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ Neither the name of the <ORGANIZATION> nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+Here are some of the functions available for now:
test_identical()
check_identical()
assert_identical()
expect_identical()
: Check if multiple objects are identical.test_identical()
check_identical()
assert_identical()
expect_identical()
: Check if multiple objects are identical.
test_length()
check_length()
assert_length()
expect_length()
: Check if an argument has a specific length.test_length()
check_length()
assert_length()
expect_length()
: Check if an argument has a specific length.
test_pick()
check_pick()
assert_pick()
: Check how many arguments were picked.test_pick()
check_pick()
assert_pick()
: Check how many arguments were picked.
Click here to see the full list of functions.
diff --git a/pkgdown.yml b/pkgdown.yml index cbcdcb6..82cb998 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -2,7 +2,7 @@ pandoc: 3.1.11 pkgdown: 2.1.1 pkgdown_sha: ~ articles: {} -last_built: 2024-10-17T07:50Z +last_built: 2024-10-18T03:04Z urls: reference: https://danielvartan.github.io/prettycheck/reference article: https://danielvartan.github.io/prettycheck/articles diff --git a/reference/assert_identical.html b/reference/assert_identical.html index aa909fb..a8e17b1 100644 --- a/reference/assert_identical.html +++ b/reference/assert_identical.html @@ -1,8 +1,8 @@ - + - + diff --git a/reference/assert_length.html b/reference/assert_length.html index a77715d..ea1fe7d 100644 --- a/reference/assert_length.html +++ b/reference/assert_length.html @@ -1,8 +1,8 @@ - + - + diff --git a/reference/assert_pick.html b/reference/assert_pick.html index 5be1327..82b979a 100644 --- a/reference/assert_pick.html +++ b/reference/assert_pick.html @@ -1,8 +1,8 @@ - + - + diff --git a/reference/check_identical.html b/reference/check_identical.html index aa909fb..a424531 100644 --- a/reference/check_identical.html +++ b/reference/check_identical.html @@ -1,8 +1,141 @@ - - - - - - - + +check_identical(..., type = "value", .names = get_names(...))
+
+assert_identical(..., type = "value", .names = get_names(...))
+
+test_identical(..., type = "value", .names = get_names(...))
Objects to compare.
(optional) a string corresponding to the type of comparison to
+perform. Valid values: "value"
, "length"
, and "class"
(default:
+"value"
).
(optional) a character vector
+containing names for each object in ...
(default:
+prettycheck:::get_names(...)
). This argument is used internally and
+should not be set by the user.
test_*
: TRUE
if it passes the test; FALSE
otherwise.
check_*
: TRUE
if it passes the test; a string with a message otherwise.
assertion_*
: The same input as invisible if it passes the
+test; an error message otherwise.
expect_*
: The same input as invisible if it passes the
+test; an error message otherwise.
x <- 1; y <- 1
+test_identical(x, y, type = "value")
+#> [1] TRUE
+#> [1] TRUE # Expected
+
+x <- 1; y <- 2
+check_identical(x, y, type = "value") |> cli::cli_alert_warning()
+#> ! x and y must have identical values.
+#> ! x and y must have identical values. # Expected
+
+x <- letters; y <- 1:2
+check_identical(x, y, type = "length") |> cli::cli_alert_warning()
+#> ! x and y must have identical lengths.
+#> ! x and y must have identical lengths. # Expected
+
+x <- "a"; y <- 1
+check_identical(x, y, type = "class") |> cli::cli_alert_warning()
+#> ! x and y must belong to the same class.
+#> ! x and y must belong to the same class. # Expected
+
check_length(
+ x,
+ len = 1,
+ min_len = NULL,
+ max_len = NULL,
+ null_ok = FALSE,
+ .names = deparse(substitute(x))
+)
+
+assert_length(
+ x,
+ len = 1,
+ min_len = NULL,
+ max_len = NULL,
+ null_ok = FALSE,
+ .names = deparse(substitute(x))
+)
+
+test_length(
+ x,
+ len = 1,
+ min_len = NULL,
+ max_len = NULL,
+ null_ok = FALSE,
+ .names = deparse(substitute(x))
+)
An R object.
(optional) an integer number indicating the expected length of x
+(default: 1
).
(optional) an integer number indicating the minimum length of
+x
(default: NULL
).
(optional) an integer number indicating the maximum length of
+x
(default: NULL
).
(optional) a logical
flag indicating
+if x
can be NULL
(default: FALSE
).
(optional) a character vector
+containing names for each object in ...
(default:
+deparse(substitute(x))
). This argument is used internally and should
+not be set by the user.
test_*
: TRUE
if it passes the test; FALSE
otherwise.
check_*
: TRUE
if it passes the test; a string with a message otherwise.
assertion_*
: The same input as invisible if it passes the
+test; an error message otherwise.
expect_*
: The same input as invisible if it passes the
+test; an error message otherwise.
x <- 1:2
+
+test_length(x, len = 2)
+#> [1] TRUE
+#> [1] TRUE # Expected
+
+check_length(x, len = 1) |> cli::cli_alert_warning()
+#> ! x must have 1 element.
+#> ! x must have 1 element. # Expected
+
+check_length(x, min_len = 3) |> cli::cli_alert_warning()
+#> ! x must have 3 or more elements.
+#> ! x must have 3 or more elements. # Expected
+
+check_length(x, max_len = 1) |> cli::cli_alert_warning()
+#> ! x must have 1 or less elements.
+#> ! x must have 1 or less elements. # Expected
+
+x <- 1
+check_length(x, min_len = 2, max_len = 3) |> cli::cli_alert_warning()
+#> ! x must have a length between 2 and 3.
+#> ! x must have a length between 2 and 3. # Expected
+
check_pick(
+ ...,
+ pick = NULL,
+ min_pick = NULL,
+ max_pick = NULL,
+ .names = get_names(...)
+)
+
+assert_pick(
+ ...,
+ pick = NULL,
+ min_pick = NULL,
+ max_pick = NULL,
+ .names = get_names(...)
+)
+
+test_pick(
+ ...,
+ pick = NULL,
+ min_pick = NULL,
+ max_pick = NULL,
+ .names = get_names(...)
+)
Objects to compare.
(optional) an integer number indicating the expected number of
+arguments to pick (default: NULL
) (default: 1
).
(optional) an integer number indicating the minimum number of
+arguments to pick (default: NULL
).
(optional) an integer number indicating the maximum number of
+arguments to pick (default: NULL
).
(optional) a character vector
+containing names for each object in ...
(default:
+prettycheck:::get_names(...)
). This argument is used internally and
+should not be set by the user.
test_*
: TRUE
if it passes the test; FALSE
otherwise.
check_*
: TRUE
if it passes the test; a string with a message otherwise.
assertion_*
: The same input as invisible if it passes the
+test; an error message otherwise.
expect_*
: The same input as invisible if it passes the
+test; an error message otherwise.
x <- 1; y <- NULL
+test_pick(x, y, pick = 1)
+#> [1] TRUE
+#> [1] TRUE # Expected
+
+x <- 1; y <- NULL; z <- NULL
+check_pick(x, y, z, pick = 2) |> cli::cli_alert_warning()
+#> ! You must pick 2 of the x, y and z arguments.
+#> ! You must pick 2 of the x, y and z arguments. # Expected
+
+x <- 1; y <- NULL
+check_pick(x, y, min_pick = 2) |> cli::cli_alert_warning()
+#> ! You must assign the x and y arguments.
+#> ! You must assign the x and y arguments. # Expected
+
+x <- 1; y <- NULL; z <- NULL
+check_pick(x, y, z, min_pick = 2) |> cli::cli_alert_warning()
+#> ! You must pick 2 or more of the x, y and z arguments.
+#> ! You must pick 2 or more of the x, y and z arguments. # Expected
+
+x <- 1; y <- 1; z <- NULL
+check_pick(x, y, z, max_pick = 1) |> cli::cli_alert_warning()
+#> ! You must pick 1 or less of the x, y and z arguments.
+#> ! You must pick 1 or less of the x, y and z arguments. # Expected
+
prettycheck
includes four main types of functions: test_*()
, check_*()
, assert_*()
, and expect_*()
. The test_*()
functions return a logical flag; the check_*()
functions return a logical flag and throw a warning message if the condition is not met; and theassert_*()
and expect_*()
functions return a logical flag and throw an error if the condition is not met.
test_identical()
check_identical()
assert_identical()
expect_identical()
Check if multiple objects are identical
test_length()
check_length()
assert_length()
expect_length()
Check if an argument has a specific length
Check how many arguments were picked
test_identical(..., type = "value")
-
-check_identical(..., type = "value")
-
-assert_identical(..., type = "value")
-
-expect_identical(..., type = "value")
test_*
: TRUE
if it passes the test; FALSE
otherwise.
check_*
: The same input as invisible if it passes the
-test; a warning message otherwise.
assertion_*
: The same input as invisible if it passes the
-test; an error message otherwise.
expect_*
: The same input as invisible if it passes the
-test; an error message otherwise.
x <- 1; y <- 1
-test_identical(x, y, type = "value")
-#> [1] TRUE
-#> [1] TRUE # Expected
-
-x <- 1; y <- 2
-check_identical(x, y, type = "value")
-#> ! x and y must have identical values.
-#> ! x and y must have identical values. # Expected
-
-x <- letters; y <- LETTERS
-test_identical(x, y, type = "length")
-#> [1] TRUE
-#> [1] TRUE # Expected
-
-x <- letters; y <- 1:2
-check_identical(x, y, type = "length")
-#> ! x and y must have identical lengths.
-#> ! x and y must have identical lengths. # Expected
-
-x <- "a"; y <- c("a", "b")
-test_identical(x, y, type = "class")
-#> [1] TRUE
-#> [1] TRUE # Expected
-
-x <- "a"; y <- 1
-check_identical(x, y, type = "class")
-#> ! x and y must belong to the same class.
-#> ! x and y must belong to the same class. # Expected
-
test_length(x, len = NULL, min_len = NULL, max_len = NULL, null_ok = FALSE)
-
-check_length(x, len = NULL, min_len = NULL, max_len = NULL, null_ok = FALSE)
-
-assert_length(x, len = NULL, min_len = NULL, max_len = NULL, null_ok = FALSE)
-
-expect_length(x, len = NULL, min_len = NULL, max_len = NULL, null_ok = FALSE)
An R object.
(optional) an integer number indicating the expected length of x
-(default: NULL
).
(optional) an integer number indicating the minimum length of
-x
(default: NULL
).
(optional) an integer number indicating the maximum length of
-x
(default: NULL
).
(optional) a logical
flag indicating
-if x
can be NULL
(default: FALSE
).
test_*
: TRUE
if it passes the test; FALSE
otherwise.
check_*
: The same input as invisible if it passes the
-test; a warning message otherwise.
assertion_*
: The same input as invisible if it passes the
-test; an error message otherwise.
expect_*
: The same input as invisible if it passes the
-test; an error message otherwise.
test_length(1, len = 1)
-#> [1] TRUE
-#> [1] TRUE # Expected
-
test_pick(..., pick = NULL, min_pick = NULL, max_pick = NULL)
-
-check_pick(..., pick = NULL, min_pick = NULL, max_pick = NULL)
-
-assert_pick(..., pick = NULL, min_pick = NULL, max_pick = NULL)
Objects to compare.
(optional) an integer number indicating the expected number of
-arguments to pick (default: NULL
) (default: 1
).
(optional) an integer number indicating the minimum number of
-arguments to pick (default: NULL
).
(optional) an integer number indicating the maximum number of
-arguments to pick (default: NULL
).
test_*
: TRUE
if it passes the test; FALSE
otherwise.
check_*
: The same input as invisible if it passes the
-test; a warning message otherwise.
assertion_*
: The same input as invisible if it passes the
-test; an error message otherwise.
expect_*
: The same input as invisible if it passes the
-test; an error message otherwise.
x <- 1; y <- NULL
-test_pick(x, y, pick = 1)
-#> [1] TRUE
-#> [1] TRUE # Expected
-
-x <- 1; y <- NULL; z <- NULL
-check_pick(x, y, z, pick = 2)
-#> ! You must pick 2 of the x, y and z arguments.
-#> ! You must pick 2 of the x, y and z arguments. # Expected
-
-x <- 1; y <- NULL
-test_pick(x, y, min_pick = 1)
-#> [1] TRUE
-#> [1] TRUE # Expected
-
-x <- 1; y <- NULL; z <- NULL
-check_pick(x, y, z, min_pick = 2)
-#> Error in else_error(): Something has gone wrong. Please report this issue at
-#> <https://github.com/danielvartan/prettycheck/issues>.
-#> ! You must pick 2 or more arguments. # Expected
-
-x <- 1; y <- 1; z <- NULL
-test_pick(x, y, z, max_pick = 1)
-#> [1] FALSE
-#> [1] FALSE # Expected
-
-x <- 1; y <- 1; z <- NULL
-check_pick(x, y, max_pick = 1)
-#> Error in else_error(): Something has gone wrong. Please report this issue at
-#> <https://github.com/danielvartan/prettycheck/issues>.
-#> ! You must pick 1 or less arguments. # Expected
-