assertions {tern} | R Documentation |
Additional assertions to use with checkmate
Description
Additional assertion functions which can be used together with the checkmate
package.
Usage
assert_list_of_variables(x, .var.name = checkmate::vname(x), add = NULL)
assert_df_with_variables(
df,
variables,
na_level = NULL,
.var.name = checkmate::vname(df),
add = NULL
)
assert_valid_factor(
x,
min.levels = 1,
max.levels = NULL,
null.ok = TRUE,
any.missing = TRUE,
n.levels = NULL,
len = NULL,
.var.name = checkmate::vname(x),
add = NULL
)
assert_df_with_factors(
df,
variables,
min.levels = 1,
max.levels = NULL,
any.missing = TRUE,
na_level = NULL,
.var.name = checkmate::vname(df),
add = NULL
)
assert_proportion_value(x, include_boundaries = FALSE)
Arguments
x |
( |
.var.name |
[ |
add |
[ |
df |
( |
variables |
(named |
na_level |
( |
min.levels |
[ |
max.levels |
[ |
null.ok |
[ |
any.missing |
[ |
n.levels |
[ |
len |
[ |
include_boundaries |
( |
Value
Nothing if assertion passes, otherwise prints the error message.
Functions
-
assert_list_of_variables()
: Checks whetherx
is a valid list of variable names.NULL
elements of the listx
are dropped withFilter(Negate(is.null), x)
. -
assert_df_with_variables()
: Check whetherdf
is a data frame with the analysisvariables
. Please notice how this produces an error when not all variables are present in the data.frame while the opposite is not required. -
assert_valid_factor()
: Check whetherx
is a valid factor (i.e. has levels and no empty string levels). Note thatNULL
andNA
elements are allowed. -
assert_df_with_factors()
: Check whetherdf
is a data frame where the analysisvariables
are all factors. Note that the creation ofNA
by direct call offactor()
will trimNA
levels out of the vector list itself. -
assert_proportion_value()
: Check whetherx
is a proportion: number between 0 and 1.
Examples
x <- data.frame(
a = 1:10,
b = rnorm(10)
)
assert_df_with_variables(x, variables = list(a = "a", b = "b"))
x <- ex_adsl
assert_df_with_variables(x, list(a = "ARM", b = "USUBJID"))
x <- ex_adsl
assert_df_with_factors(x, list(a = "ARM"))
assert_proportion_value(0.95)
assert_proportion_value(1.0, include_boundaries = TRUE)