Title: | Utility Functions and Development Tools for the Admiral Package Family |
---|---|
Description: | Utility functions to check data, variables and conditions for functions used in 'admiral' and 'admiral' extension packages. Additional utility helper functions to assist developers with maintaining documentation, testing and general upkeep of 'admiral' and 'admiral' extension packages. |
Authors: | Ben Straub [aut, cre], Stefan Bundfuss [aut] , Jeffrey Dickinson [aut], Ross Farrugia [aut], Fanny Gautier [aut], Edoardo Mancini [aut] , Sadchla Mascary [aut], Gordon Miller [aut], Daniel Sjoberg [aut] , Stefan Thoma [aut] , Kangjie Zhang [aut], Zelos Zhu [aut], F. Hoffmann-La Roche AG [cph, fnd], GlaxoSmithKline LLC [cph, fnd] |
Maintainer: | Ben Straub <[email protected]> |
License: | Apache License (>= 2) |
Version: | 1.1.0.9006 |
Built: | 2024-11-07 12:26:26 UTC |
Source: | https://github.com/pharmaverse/admiraldev |
Returns a logical
vector indicating if there is no match of the
left operand in the right operand.
x %notin% table
x %notin% table
x |
The values to be matched |
table |
The values to be matched against |
A logical
vector
Developer Utility Functions:
%or%()
,
arg_name()
,
contains_vars()
,
convert_dtm_to_dtc()
,
extract_vars()
,
filter_if()
,
friendly_type_of()
,
valid_time_units()
,
vars2chr()
Or
lhs %or% rhs
lhs %or% rhs
lhs |
Any valid R expression |
rhs |
Any valid R expression |
The function evaluates the expression lhs
and if this expression results
in an error, it catches that error and proceeds with evaluating the expression
rhs
and returns that result.
Either the result of evaluating lhs
, rhs
or an error
Developer Utility Functions:
%notin%()
,
arg_name()
,
contains_vars()
,
convert_dtm_to_dtc()
,
extract_vars()
,
filter_if()
,
friendly_type_of()
,
valid_time_units()
,
vars2chr()
Add a suffix to variables in a list of expressions
add_suffix_to_vars(order, vars, suffix)
add_suffix_to_vars(order, vars, suffix)
order |
List of expressions Permitted Values: list of variables or |
vars |
Variables to change Permitted Values: list of variables created by |
suffix |
Suffix Permitted Values: A character scalar |
The list of expression where for each element the suffix (suffix
) is
added to every symbol specified for vars
Helpers for working with Quosures:
expr_c()
,
replace_symbol_in_expr()
,
replace_values_by_names()
library(dplyr, warn.conflicts = FALSE) library(rlang) add_suffix_to_vars(exprs(ADT, desc(AVAL), AVALC), vars = exprs(AVAL), suffix = ".join")
library(dplyr, warn.conflicts = FALSE) library(rlang) add_suffix_to_vars(exprs(ADT, desc(AVAL), AVALC), vars = exprs(AVAL), suffix = ".join")
The *_join()
functions from {dplyr}
without a warning on different attributes
in datasets.
anti_join(x, y, by = NULL, copy = FALSE, ...) inner_join(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...) left_join(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...)
anti_join(x, y, by = NULL, copy = FALSE, ...) inner_join(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...) left_join(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...)
x |
|
y |
|
by |
|
copy |
|
... |
Additional arguments |
suffix |
|
data.frame
Extract Argument Name from an Expression
arg_name(expr)
arg_name(expr)
expr |
An expression created inside a function using |
character
vector
Developer Utility Functions:
%notin%()
,
%or%()
,
contains_vars()
,
convert_dtm_to_dtc()
,
extract_vars()
,
filter_if()
,
friendly_type_of()
,
valid_time_units()
,
vars2chr()
Checks if an argument is an atomic vector
assert_atomic_vector( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_atomic_vector", call = parent.frame() )
assert_atomic_vector( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_atomic_vector", call = parent.frame() )
arg |
A function argument to be checked |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not an atomic vector.
Otherwise, the input is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(x) { assert_atomic_vector(x) } example_fun(1:10) try(example_fun(list(1, 2)))
example_fun <- function(x) { assert_atomic_vector(x) } example_fun(1:10) try(example_fun(list(1, 2)))
Checks if an argument is a character scalar and (optionally) whether it matches
one of the provided values
.
assert_character_scalar( arg, values = NULL, case_sensitive = TRUE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_character_scalar", call = parent.frame() )
assert_character_scalar( arg, values = NULL, case_sensitive = TRUE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_character_scalar", call = parent.frame() )
arg |
A function argument to be checked |
values |
A |
case_sensitive |
Should the argument be handled case-sensitive?
If set to |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a character vector or if arg
is a character vector but of length > 1 or if its value is not one of the values
specified. Otherwise, the input is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(msg_type) { assert_character_scalar(msg_type, values = c("warning", "error")) } example_fun("warning") try(example_fun("message")) try(example_fun(TRUE)) # handling arguments case-insensitive example_fun2 <- function(msg_type) { msg_type <- assert_character_scalar( msg_type, values = c("warning", "error"), case_sensitive = FALSE ) if (msg_type == "warning") { print("A warning was requested.") } } example_fun2("Warning")
example_fun <- function(msg_type) { assert_character_scalar(msg_type, values = c("warning", "error")) } example_fun("warning") try(example_fun("message")) try(example_fun(TRUE)) # handling arguments case-insensitive example_fun2 <- function(msg_type) { msg_type <- assert_character_scalar( msg_type, values = c("warning", "error"), case_sensitive = FALSE ) if (msg_type == "warning") { print("A warning was requested.") } } example_fun2("Warning")
Checks if an argument is a character vector
assert_character_vector( arg, values = NULL, named = FALSE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_character_vector", call = parent.frame() )
assert_character_vector( arg, values = NULL, named = FALSE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_character_vector", call = parent.frame() )
arg |
A function argument to be checked |
values |
A |
named |
If set to |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a character vector or if
any element is not included in the list of valid values. Otherwise, the input
is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(chr) { assert_character_vector(chr) } example_fun(letters) try(example_fun(1:10)) example_fun2 <- function(chr) { assert_character_vector(chr, named = TRUE) } try(example_fun2(c(alpha = "a", "b", gamma = "c")))
example_fun <- function(chr) { assert_character_vector(chr) } example_fun(letters) try(example_fun(1:10)) example_fun2 <- function(chr) { assert_character_vector(chr, named = TRUE) } try(example_fun2(c(alpha = "a", "b", gamma = "c")))
Checks if an argument is a data frame and (optionally) whether is contains a set of required variables
assert_data_frame( arg, required_vars = NULL, check_is_grouped = TRUE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_data_frame", call = parent.frame() )
assert_data_frame( arg, required_vars = NULL, check_is_grouped = TRUE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_data_frame", call = parent.frame() )
arg |
A function argument to be checked |
required_vars |
A list of variables created using |
check_is_grouped |
Throw an error is |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a data frame or if arg
is a
data frame but misses any variable specified in required_vars
. Otherwise,
the input is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
library(dplyr) library(rlang) dm <- tribble( ~STUDYID, ~USUBJID, "XYZ", "1", "XYZ", "2" ) example_fun <- function(dataset) { assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) } example_fun(dm) try(example_fun(select(dm, -STUDYID))) try(example_fun("Not a dataset")) try(example_fun(group_by(dm, USUBJID)))
library(dplyr) library(rlang) dm <- tribble( ~STUDYID, ~USUBJID, "XYZ", "1", "XYZ", "2" ) example_fun <- function(dataset) { assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) } example_fun(dm) try(example_fun(select(dm, -STUDYID))) try(example_fun("Not a dataset")) try(example_fun(group_by(dm, USUBJID)))
Checks if a variable in a dataset is a date or datetime variable
assert_date_var( dataset, var, dataset_name = rlang::caller_arg(dataset), var_name = rlang::caller_arg(var), message = NULL, class = "assert_date_var", call = parent.frame() )
assert_date_var( dataset, var, dataset_name = rlang::caller_arg(dataset), var_name = rlang::caller_arg(var), message = NULL, class = "assert_date_var", call = parent.frame() )
dataset |
The dataset where the variable is expected |
var |
The variable to check |
dataset_name |
The name of the dataset. If the argument is specified, the specified name is displayed in the error message. |
var_name |
The name of the variable. If the argument is specified, the specified name is displayed in the error message. |
message |
( |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if var
is not a date or datetime variable in
dataset
and returns the input invisibly otherwise.
library(lubridate) library(dplyr) library(rlang) example_fun <- function(dataset, var) { var <- assert_symbol(enexpr(var)) assert_date_var(dataset = dataset, var = !!var) } my_data <- tribble( ~USUBJID, ~ADT, "1", ymd("2020-12-06"), "2", ymd("") ) example_fun( dataset = my_data, var = ADT ) try(example_fun( dataset = my_data, var = USUBJID )) example_fun2 <- function(dataset, var) { var <- assert_symbol(enexpr(var)) assert_date_var( dataset = dataset, var = !!var, dataset_name = "your_data", var_name = "your_var" ) } try(example_fun2( dataset = my_data, var = USUBJID ))
library(lubridate) library(dplyr) library(rlang) example_fun <- function(dataset, var) { var <- assert_symbol(enexpr(var)) assert_date_var(dataset = dataset, var = !!var) } my_data <- tribble( ~USUBJID, ~ADT, "1", ymd("2020-12-06"), "2", ymd("") ) example_fun( dataset = my_data, var = ADT ) try(example_fun( dataset = my_data, var = USUBJID )) example_fun2 <- function(dataset, var) { var <- assert_symbol(enexpr(var)) assert_date_var( dataset = dataset, var = !!var, dataset_name = "your_data", var_name = "your_var" ) } try(example_fun2( dataset = my_data, var = USUBJID ))
Check if an object/vector is a date or datetime variable without needing a dataset as input
assert_date_vector( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_date_vector", call = parent.frame() )
assert_date_vector( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_date_vector", call = parent.frame() )
arg |
The function argument to be checked |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function returns an error if arg
is missing, or not a date or datetime variable
but otherwise returns an invisible output.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(arg) { assert_date_vector(arg) } example_fun( as.Date("2022-01-30", tz = "UTC") ) try(example_fun("1993-07-14"))
example_fun <- function(arg) { assert_date_vector(arg) } example_fun( as.Date("2022-01-30", tz = "UTC") ) try(example_fun("1993-07-14"))
Assert Argument is an Expression
assert_expr( arg, optional = FALSE, arg_name = gsub("^enexpr\\((.*)\\)$", "\\1", rlang::caller_arg(arg)), message = NULL, class = "assert_expr", call = parent.frame() )
assert_expr( arg, optional = FALSE, arg_name = gsub("^enexpr\\((.*)\\)$", "\\1", rlang::caller_arg(arg)), message = NULL, class = "assert_expr", call = parent.frame() )
arg |
A function argument to be checked |
optional |
Is the checked argument optional? If set to |
arg_name |
By default the expression specified for |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not an expression, i.e. either
a symbol or a call, or returns the input invisibly otherwise
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
Checks if the argument is a list of expressions.
assert_expr_list( arg, required_elements = NULL, named = FALSE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_expr_list", call = parent.frame() )
assert_expr_list( arg, required_elements = NULL, named = FALSE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_expr_list", call = parent.frame() )
arg |
A function argument to be checked |
required_elements |
A |
named |
If set to |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a list of expressions.
Otherwise, the input it returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
library(rlang) example_fun <- function(vars) { assert_expr_list(vars) } example_fun(exprs(DTHDOM = "AE", DTHSEQ = AESEQ)) try(example_fun(exprs("AE", DTSEQ = AESEQ, !!list("a"), !!list("a"))))
library(rlang) example_fun <- function(vars) { assert_expr_list(vars) } example_fun(exprs(DTHDOM = "AE", DTHSEQ = AESEQ)) try(example_fun(exprs("AE", DTSEQ = AESEQ, !!list("a"), !!list("a"))))
Is an Argument a Filter Condition?
assert_filter_cond( arg, optional = FALSE, arg_name = gsub("^enexpr\\((.*)\\)$", "\\1", rlang::caller_arg(arg)), message = NULL, class = "assert_filter_cond", call = parent.frame() )
assert_filter_cond( arg, optional = FALSE, arg_name = gsub("^enexpr\\((.*)\\)$", "\\1", rlang::caller_arg(arg)), message = NULL, class = "assert_filter_cond", call = parent.frame() )
arg |
Quosure - filtering condition. |
optional |
Logical - is the argument optional? Defaults to |
arg_name |
By default the expression specified for |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
Check if arg
is a suitable filtering condition to be used in
functions like subset
or dplyr::filter
.
Performs necessary checks and returns arg
if all pass.
Otherwise throws an informative error.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
library(dplyr, warn.conflicts = FALSE) library(rlang) dm <- dplyr::tribble( ~DOMAIN, ~STUDYID, ~USUBJID, ~AGE, "DM", "STUDY X", "01-701-1015", 64, "DM", "STUDY X", "01-701-1016", 65, ) # typical usage in a function as an argument check example_fun <- function(dat, x) { x <- assert_filter_cond(enexpr(x), arg_name = "x") filter(dat, !!x) } example_fun(dm, AGE == 64) try(assert_filter_cond(mtcars))
library(dplyr, warn.conflicts = FALSE) library(rlang) dm <- dplyr::tribble( ~DOMAIN, ~STUDYID, ~USUBJID, ~AGE, "DM", "STUDY X", "01-701-1015", 64, "DM", "STUDY X", "01-701-1016", 65, ) # typical usage in a function as an argument check example_fun <- function(dat, x) { x <- assert_filter_cond(enexpr(x), arg_name = "x") filter(dat, !!x) } example_fun(dm, AGE == 64) try(assert_filter_cond(mtcars))
Checks if the argument is a function and if all expected arguments are provided by the function.
assert_function( arg, params = NULL, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_function", call = parent.frame() )
assert_function( arg, params = NULL, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_function", call = parent.frame() )
arg |
A function The function to be checked |
params |
A character vector A character vector of expected argument names for the aforementioned function in |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error
if the argument is not a function or
if the function does not provide all arguments as specified for the
params
argument (assuming ellipsis is not in function formals)
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(fun) { assert_function(fun, params = c("x")) } example_fun(mean) try(example_fun(1)) try(example_fun(sum))
example_fun <- function(fun) { assert_function(fun, params = c("x")) } example_fun(mean) try(example_fun(1)) try(example_fun(sum))
Checks if an argument is an integer scalar
assert_integer_scalar( arg, subset = "none", optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_integer_scalar", call = parent.frame() )
assert_integer_scalar( arg, subset = "none", optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_integer_scalar", call = parent.frame() )
arg |
A function argument to be checked |
subset |
A subset of integers that |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not an integer belonging to the
specified subset
. Otherwise, the input is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(num1, num2) { assert_integer_scalar(num1, subset = "positive") assert_integer_scalar(num2, subset = "negative") } example_fun(1, -9) try(example_fun(1.5, -9)) try(example_fun(2, 0)) try(example_fun("2", 0))
example_fun <- function(num1, num2) { assert_integer_scalar(num1, subset = "positive") assert_integer_scalar(num2, subset = "negative") } example_fun(1, -9) try(example_fun(1.5, -9)) try(example_fun(2, 0)) try(example_fun("2", 0))
Checks if the elements of a list of named lists/classes fulfill a certain condition. If not, an error is issued and all elements of the list not fulfilling the condition are listed.
assert_list_element( list, element, condition, message_text, arg_name = rlang::caller_arg(list), message = NULL, class = "assert_list_element", call = parent.frame(), ... )
assert_list_element( list, element, condition, message_text, arg_name = rlang::caller_arg(list), message = NULL, class = "assert_list_element", call = parent.frame(), ... )
list |
A list to be checked A list of named lists or classes is expected. |
element |
The name of an element of the lists/classes A character scalar is expected. |
condition |
Condition to be fulfilled
The condition is evaluated for each element of the list. The element of the
lists/classes can be referred to by its name, e.g., |
message_text |
Text to be displayed in the error message above
the listing of values that do not meet the condition.
The text should describe the condition to be fulfilled,
e.g., |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
... |
Objects required to evaluate the condition or the message text If the condition or the message text contains objects apart from the element, they have to be passed to the function. See the second example below. |
An error if the condition is not met. The input otherwise.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
death <- list( dataset_name = "adsl", date = "DTHDT", censor = 0 ) lstalv <- list( dataset_name = "adsl", date = "LSTALVDT", censor = 1 ) events <- list(death, lstalv) try(assert_list_element( list = events, element = "censor", condition = censor == 0, message_text = "For events the censor values must be zero." )) try(assert_list_element( list = events, element = "dataset_name", condition = dataset_name %in% c("adrs", "adae"), valid_datasets = c("adrs", "adae"), message_text = paste( "The dataset name must be one of the following: {.val {valid_datasets}}" ) ))
death <- list( dataset_name = "adsl", date = "DTHDT", censor = 0 ) lstalv <- list( dataset_name = "adsl", date = "LSTALVDT", censor = 1 ) events <- list(death, lstalv) try(assert_list_element( list = events, element = "censor", condition = censor == 0, message_text = "For events the censor values must be zero." )) try(assert_list_element( list = events, element = "dataset_name", condition = dataset_name %in% c("adrs", "adae"), valid_datasets = c("adrs", "adae"), message_text = paste( "The dataset name must be one of the following: {.val {valid_datasets}}" ) ))
Checks if an argument is a list
of objects inheriting from the S3 class or type specified.
assert_list_of( arg, cls, named = FALSE, optional = TRUE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_list_of", call = parent.frame() )
assert_list_of( arg, cls, named = FALSE, optional = TRUE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_list_of", call = parent.frame() )
arg |
A function argument to be checked |
cls |
The S3 class or type to check for |
named |
If set to |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a list or if arg
is a list but
its elements are not objects inheriting from class
or of type class
.
Otherwise, the input is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(list) { assert_list_of(list, "data.frame") } example_fun(list(mtcars, iris)) try(example_fun(list(letters, 1:10))) try(example_fun(c(TRUE, FALSE))) example_fun2 <- function(list) { assert_list_of(list, "numeric", named = TRUE) } try(example_fun2(list(1, 2, 3, d = 4)))
example_fun <- function(list) { assert_list_of(list, "data.frame") } example_fun(list(mtcars, iris)) try(example_fun(list(letters, 1:10))) try(example_fun(c(TRUE, FALSE))) example_fun2 <- function(list) { assert_list_of(list, "numeric", named = TRUE) } try(example_fun2(list(1, 2, 3, d = 4)))
Checks if an argument is a logical scalar
assert_logical_scalar( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_logical_scalar", call = parent.frame() )
assert_logical_scalar( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_logical_scalar", call = parent.frame() )
arg |
A function argument to be checked |
optional |
Is the checked argument optional? |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is neither TRUE
or FALSE
. Otherwise,
the input is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(flag) { assert_logical_scalar(flag) } example_fun(FALSE) try(example_fun(NA)) try(example_fun(c(TRUE, FALSE, FALSE))) try(example_fun(1:10))
example_fun <- function(flag) { assert_logical_scalar(flag) } example_fun(FALSE) try(example_fun(NA)) try(example_fun(c(TRUE, FALSE, FALSE))) try(example_fun(1:10))
Assert that all elements of the argument are named.
assert_named( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_named", call = parent.frame() )
assert_named( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_named", call = parent.frame() )
arg |
A function argument to be checked |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a named list or vector or
returns the input invisibly otherwise
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(varval_list) { assert_named(varval_list) } example_fun(list(var1 = 1, var2 = "x")) try(example_fun(list(1, "x"))) try(example_fun(list(var = 1, "x")))
example_fun <- function(varval_list) { assert_named(varval_list) } example_fun(list(var1 = 1, var2 = "x")) try(example_fun(list(1, "x"))) try(example_fun(list(var = 1, "x")))
Checks if an argument is a numeric vector
assert_numeric_vector( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_numeric_vector", call = parent.frame() )
assert_numeric_vector( arg, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_numeric_vector", call = parent.frame() )
arg |
A function argument to be checked |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a numeric vector.
Otherwise, the input is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(num) { assert_numeric_vector(num) } example_fun(1:10) try(example_fun(letters))
example_fun <- function(num) { assert_numeric_vector(num) } example_fun(1:10) try(example_fun(letters))
Checks if there is a one to one mapping between two lists of variables.
assert_one_to_one( dataset, vars1, vars2, dataset_name = rlang::caller_arg(dataset), message = NULL, class = "assert_one_to_one", call = parent.frame() )
assert_one_to_one( dataset, vars1, vars2, dataset_name = rlang::caller_arg(dataset), message = NULL, class = "assert_one_to_one", call = parent.frame() )
dataset |
Dataset to be checked The variables specified for |
vars1 |
First list of variables |
vars2 |
Second list of variables |
dataset_name |
string indicating the label/symbol of the object being checked.
Default is |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
An error if the condition is not meet. The input otherwise.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
library(dplyr) library(rlang) df <- tribble( ~SPECIES, ~SPECIESN, "DOG", 1L, "CAT", 2L, "DOG", 1L ) assert_one_to_one(df, vars1 = exprs(SPECIES), vars2 = exprs(SPECIESN)) df_many <- tribble( ~SPECIES, ~SPECIESN, "DOG", 1L, "CAT", 2L, "DOG", 3L ) try( assert_one_to_one(df_many, vars1 = exprs(SPECIES), vars2 = exprs(SPECIESN)) ) try( assert_one_to_one(df_many, vars1 = exprs(SPECIESN), vars2 = exprs(SPECIES)) )
library(dplyr) library(rlang) df <- tribble( ~SPECIES, ~SPECIESN, "DOG", 1L, "CAT", 2L, "DOG", 1L ) assert_one_to_one(df, vars1 = exprs(SPECIES), vars2 = exprs(SPECIESN)) df_many <- tribble( ~SPECIES, ~SPECIESN, "DOG", 1L, "CAT", 2L, "DOG", 3L ) try( assert_one_to_one(df_many, vars1 = exprs(SPECIES), vars2 = exprs(SPECIESN)) ) try( assert_one_to_one(df_many, vars1 = exprs(SPECIESN), vars2 = exprs(SPECIES)) )
Checks if a parameter (PARAMCD
) does not exist in a dataset.
assert_param_does_not_exist( dataset, param, arg_name = rlang::caller_arg(dataset), message = NULL, class = "assert_param_does_not_exist", call = parent.frame() )
assert_param_does_not_exist( dataset, param, arg_name = rlang::caller_arg(dataset), message = NULL, class = "assert_param_does_not_exist", call = parent.frame() )
dataset |
A |
param |
Parameter code to check |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if the parameter exists in the input dataset. Otherwise, the dataset is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
library(dplyr) advs <- tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, "P02", "WEIGHT", 85.7, "kg", "WEIGHT", 85.7 ) assert_param_does_not_exist(advs, param = "HR") try(assert_param_does_not_exist(advs, param = "WEIGHT"))
library(dplyr) advs <- tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, "P02", "WEIGHT", 85.7, "kg", "WEIGHT", 85.7 ) assert_param_does_not_exist(advs, param = "HR") try(assert_param_does_not_exist(advs, param = "WEIGHT"))
Checks if an argument is an object inheriting from the S3 class specified.
assert_s3_class( arg, cls, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_s3_class", call = parent.frame() )
assert_s3_class( arg, cls, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_s3_class", call = parent.frame() )
arg |
A function argument to be checked |
cls |
The S3 class to check for |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is an object which does not inherit from class
.
Otherwise, the input is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(obj) { assert_s3_class(obj, "factor") } example_fun(as.factor(letters)) try(example_fun(letters)) try(example_fun(1:10))
example_fun <- function(obj) { assert_s3_class(obj, "factor") } example_fun(as.factor(letters)) try(example_fun(letters)) try(example_fun(1:10))
Checks if all arguments are of the same type.
assert_same_type( ..., .message = c("Arguments {.arg {arg_names}} must be the same type.", i = paste("Argument types are", paste0("{.arg ", arg_names, "} {.cls ", types, "}", collapse = ", "))), .class = "assert_same_type", .call = parent.frame() )
assert_same_type( ..., .message = c("Arguments {.arg {arg_names}} must be the same type.", i = paste("Argument types are", paste0("{.arg ", arg_names, "} {.cls ", types, "}", collapse = ", "))), .class = "assert_same_type", .call = parent.frame() )
... |
Arguments to be checked |
.message |
character vector passed to |
.class |
character vector passed to |
.call |
environment passed to |
The function throws an error if not all arguments are of the same type.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
example_fun <- function(true_value, false_value, missing_value) { assert_same_type(true_value, false_value, missing_value) } example_fun( true_value = "Y", false_value = "N", missing_value = NA_character_ ) try(example_fun( true_value = 1, false_value = 0, missing_value = "missing" ))
example_fun <- function(true_value, false_value, missing_value) { assert_same_type(true_value, false_value, missing_value) } example_fun( true_value = "Y", false_value = "N", missing_value = NA_character_ ) try(example_fun( true_value = 1, false_value = 0, missing_value = "missing" ))
Checks if an argument is a symbol
assert_symbol( arg, optional = FALSE, arg_name = gsub("^enexpr\\((.*)\\)$", "\\1", rlang::caller_arg(arg)), message = NULL, class = "assert_symbol", call = parent.frame() )
assert_symbol( arg, optional = FALSE, arg_name = gsub("^enexpr\\((.*)\\)$", "\\1", rlang::caller_arg(arg)), message = NULL, class = "assert_symbol", call = parent.frame() )
arg |
A function argument to be checked. Must be a |
optional |
Is the checked argument optional? If set to |
arg_name |
By default the expression specified for |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a symbol and returns the input
invisibly otherwise.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_unit()
,
assert_vars()
,
assert_varval_list()
library(dplyr, warn.conflicts = FALSE) library(rlang) dm <- dplyr::tribble( ~DOMAIN, ~USUBJID, "DM", "01-701-1015", "DM", "01-701-1016", ) example_fun <- function(dat, var) { var <- assert_symbol(enexpr(var)) select(dat, !!var) } example_fun(dm, USUBJID) try(example_fun(dm)) try(example_fun(dm, "USUBJID")) try(example_fun(dm, toupper(PARAMCD)))
library(dplyr, warn.conflicts = FALSE) library(rlang) dm <- dplyr::tribble( ~DOMAIN, ~USUBJID, "DM", "01-701-1015", "DM", "01-701-1016", ) example_fun <- function(dat, var) { var <- assert_symbol(enexpr(var)) select(dat, !!var) } example_fun(dm, USUBJID) try(example_fun(dm)) try(example_fun(dm, "USUBJID")) try(example_fun(dm, toupper(PARAMCD)))
Checks if a parameter (PARAMCD
) in a dataset is provided in the expected
unit.
assert_unit( dataset, param, required_unit = NULL, get_unit_expr, arg_name = rlang::caller_arg(required_unit), message = NULL, class = "assert_unit", call = parent.frame() )
assert_unit( dataset, param, required_unit = NULL, get_unit_expr, arg_name = rlang::caller_arg(required_unit), message = NULL, class = "assert_unit", call = parent.frame() )
dataset |
Dataset to be checked The variable |
param |
Parameter code of the parameter to check |
required_unit |
Expected unit(s) If the argument is set to Permitted Values: A character vector or |
get_unit_expr |
Expression used to provide the unit of |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error
if there is more than one non-missing unit in the dataset or
if the unit variable differs from the expected unit for any observation of the parameter in the input dataset.
Otherwise, the dataset is returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_vars()
,
assert_varval_list()
library(dplyr) advs <- tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, "P02", "WEIGHT", 85.7, "kg", "WEIGHT", 85.7 ) assert_unit(advs, param = "WEIGHT", required_unit = "kg", get_unit_expr = VSSTRESU) try( assert_unit( advs, param = "WEIGHT", required_unit = c("g", "mg"), get_unit_expr = VSSTRESU ) ) # Checking uniqueness of unit only advs <- tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, "P02", "WEIGHT", 85700, "g", "WEIGHT", 85700 ) try( assert_unit(advs, param = "WEIGHT", get_unit_expr = VSSTRESU) )
library(dplyr) advs <- tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, "P02", "WEIGHT", 85.7, "kg", "WEIGHT", 85.7 ) assert_unit(advs, param = "WEIGHT", required_unit = "kg", get_unit_expr = VSSTRESU) try( assert_unit( advs, param = "WEIGHT", required_unit = c("g", "mg"), get_unit_expr = VSSTRESU ) ) # Checking uniqueness of unit only advs <- tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, "P02", "WEIGHT", 85700, "g", "WEIGHT", 85700 ) try( assert_unit(advs, param = "WEIGHT", get_unit_expr = VSSTRESU) )
Checks if an argument is a valid list of symbols (e.g., created by exprs()
)
assert_vars( arg, expect_names = FALSE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_vars", call = parent.frame() )
assert_vars( arg, expect_names = FALSE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_vars", call = parent.frame() )
arg |
A function argument to be checked |
expect_names |
If the argument is set to |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a list of symbols (e.g., created
by exprs()
and returns the input invisibly otherwise.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_varval_list()
library(dplyr, warn.conflicts = FALSE) library(rlang) example_fun <- function(by_vars) { assert_vars(by_vars) } example_fun(exprs(USUBJID, PARAMCD)) try(example_fun(quos(USUBJID, PARAMCD))) try(example_fun(c("USUBJID", "PARAMCD", "VISIT"))) try(example_fun(exprs(USUBJID, toupper(PARAMCD), desc(AVAL)))) example_fun_name <- function(by_vars) { assert_vars(by_vars, expect_names = TRUE) } example_fun_name(exprs(APERSDT = APxxSDT, APEREDT = APxxEDT)) try(example_fun_name(exprs(APERSDT = APxxSDT, APxxEDT)))
library(dplyr, warn.conflicts = FALSE) library(rlang) example_fun <- function(by_vars) { assert_vars(by_vars) } example_fun(exprs(USUBJID, PARAMCD)) try(example_fun(quos(USUBJID, PARAMCD))) try(example_fun(c("USUBJID", "PARAMCD", "VISIT"))) try(example_fun(exprs(USUBJID, toupper(PARAMCD), desc(AVAL)))) example_fun_name <- function(by_vars) { assert_vars(by_vars, expect_names = TRUE) } example_fun_name(exprs(APERSDT = APxxSDT, APEREDT = APxxEDT)) try(example_fun_name(exprs(APERSDT = APxxSDT, APxxEDT)))
Checks if the argument is a list of expressions where the expressions are
variable-value pairs. The value can be a symbol, a string, a numeric, an
expression, or NA
.
assert_varval_list( arg, required_elements = NULL, accept_expr = TRUE, accept_var = FALSE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_varval_list", call = parent.frame() )
assert_varval_list( arg, required_elements = NULL, accept_expr = TRUE, accept_var = FALSE, optional = FALSE, arg_name = rlang::caller_arg(arg), message = NULL, class = "assert_varval_list", call = parent.frame() )
arg |
A function argument to be checked |
required_elements |
A |
accept_expr |
Should expressions on the right hand side be accepted? |
accept_var |
Should unnamed variable names (e.g. |
optional |
Is the checked argument optional? If set to |
arg_name |
string indicating the label/symbol of the object being checked. |
message |
string passed to |
class |
Subclass of the condition. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
The function throws an error if arg
is not a list of variable-value expressions.
Otherwise, the input it returned invisibly.
Checks for valid input and returns warning or errors messages:
assert_atomic_vector()
,
assert_character_scalar()
,
assert_character_vector()
,
assert_data_frame()
,
assert_date_vector()
,
assert_expr()
,
assert_expr_list()
,
assert_filter_cond()
,
assert_function()
,
assert_integer_scalar()
,
assert_list_element()
,
assert_list_of()
,
assert_logical_scalar()
,
assert_named()
,
assert_numeric_vector()
,
assert_one_to_one()
,
assert_param_does_not_exist()
,
assert_s3_class()
,
assert_same_type()
,
assert_symbol()
,
assert_unit()
,
assert_vars()
library(dplyr, warn.conflicts = FALSE) library(rlang) example_fun <- function(vars) { assert_varval_list(vars) } example_fun(exprs(DTHDOM = "AE", DTHSEQ = AESEQ)) try(example_fun(exprs("AE", DTSEQ = AESEQ)))
library(dplyr, warn.conflicts = FALSE) library(rlang) example_fun <- function(vars) { assert_varval_list(vars) } example_fun(exprs(DTHDOM = "AE", DTHSEQ = AESEQ)) try(example_fun(exprs("AE", DTSEQ = AESEQ)))
Wrap a String in Backquotes
backquote(x)
backquote(x)
x |
A |
A character
vector
Helpers for working with Quotes and Quoting:
dquote()
,
enumerate()
,
squote()
exprs()
or
Source Variables from a List of Expressionscheck that argument contains valid variable(s) created with exprs()
or
Source Variables from a List of Expressions
contains_vars(arg)
contains_vars(arg)
arg |
A function argument to be checked |
A TRUE
if variables were valid variable
Developer Utility Functions:
%notin%()
,
%or%()
,
arg_name()
,
convert_dtm_to_dtc()
,
extract_vars()
,
filter_if()
,
friendly_type_of()
,
valid_time_units()
,
vars2chr()
Helper Function to Convert Date (or Date-time) Objects to Characters of dtc Format (-DTC type of variable)
convert_dtm_to_dtc(dtm)
convert_dtm_to_dtc(dtm)
dtm |
date or date-time |
character
vector
Developer Utility Functions:
%notin%()
,
%or%()
,
arg_name()
,
contains_vars()
,
extract_vars()
,
filter_if()
,
friendly_type_of()
,
valid_time_units()
,
vars2chr()
Output a dataset in a vignette with the pre-specified admiral format.
dataset_vignette(dataset, display_vars = NULL, filter = NULL)
dataset_vignette(dataset, display_vars = NULL, filter = NULL)
dataset |
Dataset to output in the vignette |
display_vars |
Variables selected to demonstrate the outcome of the derivation Permitted Values: list of variables Default is NULL If |
filter |
Filter condition The specified condition is applied to the dataset before it is displayed. Permitted Values: a condition |
A HTML table
Wrap a string in double quotes, e.g., for displaying character values in messages.
dquote(x)
dquote(x)
x |
A character vector |
If the input is NULL
, the text "NULL"
is returned. Otherwise, the
input in double quotes is returned.
Helpers for working with Quotes and Quoting:
backquote()
,
enumerate()
,
squote()
Enumerate multiple elements of a vector or list.
enumerate(x, quote_fun = backquote, conjunction = "and")
enumerate(x, quote_fun = backquote, conjunction = "and")
x |
A vector or list |
quote_fun |
Quoting function, defaults to |
conjunction |
Character to be used in the message, defaults to |
A character
vector
Helpers for working with Quotes and Quoting:
backquote()
,
dquote()
,
squote()
enumerate(c("one", "two", "three")) enumerate(c(1, 2, 3), quote_fun = NULL)
enumerate(c("one", "two", "three")) enumerate(c(1, 2, 3), quote_fun = NULL)
Uses diffdf::diffdf()
to compares 2 datasets for any differences. This function can be
thought of as an R-equivalent of SAS proc compare and a useful tool for unit testing as well.
expect_dfs_equal(base, compare, keys, ...)
expect_dfs_equal(base, compare, keys, ...)
base |
Input dataset |
compare |
Comparison dataset |
keys |
|
... |
Additional arguments passed onto |
An error if base
and compare
do not match or NULL
invisibly if they do
library(dplyr, warn.conflicts = FALSE) tbl1 <- tribble( ~USUBJID, ~AGE, ~SEX, "1001", 18, "M", "1002", 19, "F", "1003", 20, "M", "1004", 18, "F" ) tbl2 <- tribble( ~USUBJID, ~AGE, ~SEX, "1001", 18, "M", "1002", 18.9, "F", "1003", 20, NA ) try(expect_dfs_equal(tbl1, tbl2, keys = "USUBJID")) tlb3 <- tribble( ~USUBJID, ~AGE, ~SEX, "1004", 18, "F", "1003", 20, "M", "1002", 19, "F", "1001", 18, "M", ) # Note the sorting order of the keys is not required expect_dfs_equal(tbl1, tlb3, keys = "USUBJID")
library(dplyr, warn.conflicts = FALSE) tbl1 <- tribble( ~USUBJID, ~AGE, ~SEX, "1001", 18, "M", "1002", 19, "F", "1003", 20, "M", "1004", 18, "F" ) tbl2 <- tribble( ~USUBJID, ~AGE, ~SEX, "1001", 18, "M", "1002", 18.9, "F", "1003", 20, NA ) try(expect_dfs_equal(tbl1, tbl2, keys = "USUBJID")) tlb3 <- tribble( ~USUBJID, ~AGE, ~SEX, "1004", 18, "F", "1003", 20, "M", "1002", 19, "F", "1001", 18, "M", ) # Note the sorting order of the keys is not required expect_dfs_equal(tbl1, tlb3, keys = "USUBJID")
Concatenate One or More Expressions
expr_c(...)
expr_c(...)
... |
One or more expressions or list of expressions |
A list of expressions
Helpers for working with Quosures:
add_suffix_to_vars()
,
replace_symbol_in_expr()
,
replace_values_by_names()
Extract All Symbols from a List of Expressions
extract_vars(x, side = "lhs")
extract_vars(x, side = "lhs")
x |
An |
side |
One of |
A list of expressions
Developer Utility Functions:
%notin%()
,
%or%()
,
arg_name()
,
contains_vars()
,
convert_dtm_to_dtc()
,
filter_if()
,
friendly_type_of()
,
valid_time_units()
,
vars2chr()
library(rlang) extract_vars(exprs(PARAMCD, (BASE - AVAL) / BASE + 100)) extract_vars(AVAL ~ ARMCD + AGEGR1) extract_vars(AVAL ~ ARMCD + AGEGR1, side = "rhs")
library(rlang) extract_vars(exprs(PARAMCD, (BASE - AVAL) / BASE + 100)) extract_vars(AVAL ~ ARMCD + AGEGR1) extract_vars(AVAL ~ ARMCD + AGEGR1, side = "rhs")
Filters the input dataset if the provided expression is not NULL
filter_if(dataset, filter)
filter_if(dataset, filter)
dataset |
Input dataset |
filter |
A filter condition. Must be an expression. |
A data.frame
containing all rows in dataset
matching filter
or
just dataset
if filter
is NULL
Developer Utility Functions:
%notin%()
,
%or%()
,
arg_name()
,
contains_vars()
,
convert_dtm_to_dtc()
,
extract_vars()
,
friendly_type_of()
,
valid_time_units()
,
vars2chr()
Return English-friendly messaging for object-types
friendly_type_of(x, value = TRUE, length = FALSE)
friendly_type_of(x, value = TRUE, length = FALSE)
x |
Any R object. |
value |
Whether to describe the value of |
length |
Whether to mention the length of vectors and lists. |
This helper function aids us in forming user-friendly messages that gets
called through what_is_it()
, which is often used in the assertion functions
to identify what object-type the user passed through an argument instead of
an expected-type.
A string describing the type. Starts with an indefinite article, e.g. "an integer vector".
Developer Utility Functions:
%notin%()
,
%or%()
,
arg_name()
,
contains_vars()
,
convert_dtm_to_dtc()
,
extract_vars()
,
filter_if()
,
valid_time_units()
,
vars2chr()
Get Constant Variables
get_constant_vars(dataset, by_vars, ignore_vars = NULL)
get_constant_vars(dataset, by_vars, ignore_vars = NULL)
dataset |
A data frame. |
by_vars |
By variables The groups defined by the by variables are considered separately. I.e., if a variable is constant within each by group, it is returned. |
ignore_vars |
Variables to ignore The specified variables are not considered, i.e., they are not returned even if they are constant (unless they are included in the by variables). Permitted Values: A list of variable names or selector function calls
like |
Variable vector.
Brings something to you!?!:
get_dataset()
,
get_duplicates()
,
get_source_vars()
admiraldev_environment
environmentRetrieve a Dataset from the admiraldev_environment
environment
get_dataset(name)
get_dataset(name)
name |
The name of the dataset to retrieve |
Sometimes, developers may want to provide information to users which does not fit into a warning or error message. For example, if the input dataset of a function contains unexpected records, these can be stored in a separate dataset, which users can access to investigate the issue.
To achieve this, R has a data structure known as an 'environment'. These environment objects are created at build time, but can be populated with values after the package has been loaded and update those values over the course of an R session.
As so, the establishment of admiraldev_environment
allows us to create dynamic data/objects
based on user-inputs that need modification. The purpose of get_dataset
is to
retrieve the datasets contained inside admiraldev_environment
.
Currently we only support two datasets inside our admiraldev_environment
object:
one_to_many
many_to_one
A data.frame
Brings something to you!?!:
get_constant_vars()
,
get_duplicates()
,
get_source_vars()
Get Duplicates From a Vector
get_duplicates(x)
get_duplicates(x)
x |
An atomic vector |
A vector of the same type as x
contain duplicate values
Brings something to you!?!:
get_constant_vars()
,
get_dataset()
,
get_source_vars()
get_duplicates(1:10) get_duplicates(c("a", "a", "b", "c", "d", "d"))
get_duplicates(1:10) get_duplicates(c("a", "a", "b", "c", "d", "d"))
Get a New Temporary Variable Name for a Dataset
get_new_tmp_var(dataset, prefix = "tmp_var")
get_new_tmp_var(dataset, prefix = "tmp_var")
dataset |
The input dataset |
prefix |
The prefix of the new temporary variable name to create |
The function returns a new unique temporary variable name to be used inside
dataset
. The temporary variable names have the structure prefix_n
where
n
is an integer, e.g. tmp_var_1
. If there is already a variable inside
datset
with a given prefix
then the suffix is increased by 1, e.g. if
tmp_var_1
already exists then get_new_tmp_var()
will return tmp_var_2
.
The name of a new temporary variable as a symbol
library(dplyr, warn.conflicts = FALSE) dm <- tribble( ~DOMAIN, ~STUDYID, ~USUBJID, "DM", "STUDY X", "01-701-1015", "DM", "STUDY X", "01-701-1016", ) tmp_var <- get_new_tmp_var(dm) mutate(dm, !!tmp_var := NA)
library(dplyr, warn.conflicts = FALSE) dm <- tribble( ~DOMAIN, ~STUDYID, ~USUBJID, "DM", "STUDY X", "01-701-1015", "DM", "STUDY X", "01-701-1016", ) tmp_var <- get_new_tmp_var(dm) mutate(dm, !!tmp_var := NA)
Get Source Variables from a List of Expressions
get_source_vars(expressions)
get_source_vars(expressions)
expressions |
A list of expressions |
A list of expressions
Brings something to you!?!:
get_constant_vars()
,
get_dataset()
,
get_duplicates()
Checks if the argument equals the auto keyword
is_auto(arg)
is_auto(arg)
arg |
argument to check |
TRUE
if the argument equals the auto keyword, i.e., it is an
expression of a symbol named auto.
Identifies type of Object with return of TRUE/FALSE:
is_order_vars()
,
is_valid_dtc()
Check if inputs are created using exprs()
or calls involving desc()
is_order_vars(arg)
is_order_vars(arg)
arg |
An R object |
FALSE
if the argument is not a list of order vars
Identifies type of Object with return of TRUE/FALSE:
is_auto()
,
is_valid_dtc()
Is this string a valid DTC
is_valid_dtc(arg)
is_valid_dtc(arg)
arg |
A |
TRUE
if the argument is a valid --DTC
string, FALSE
otherwise
Identifies type of Object with return of TRUE/FALSE:
is_auto()
,
is_order_vars()
set_values_to
ArgumentThe function creates the variables specified by the set_values_to
argument,
catches errors, provides user friendly error messages, and optionally checks
the type of the created variables.
process_set_values_to(dataset, set_values_to = NULL, expected_types = NULL)
process_set_values_to(dataset, set_values_to = NULL, expected_types = NULL)
dataset |
Input dataset |
set_values_to |
Variables to set A named list returned by |
expected_types |
If the argument is specified, the specified variables are checked whether
the specified type matches the type of the variables created by
Permitted Values: A character vector with values |
The input dataset with the variables specified by set_values_to
added/updated
library(dplyr) data <- tribble( ~AVAL, 20 ) try( process_set_values_to( data, set_values_to = exprs( PARAMCD = BMI ) ) ) try( process_set_values_to( data, set_values_to = exprs( PARAMCD = 42 ), expected_types = c(PARAMCD = "character") ) )
library(dplyr) data <- tribble( ~AVAL, 20 ) try( process_set_values_to( data, set_values_to = exprs( PARAMCD = BMI ) ) ) try( process_set_values_to( data, set_values_to = exprs( PARAMCD = 42 ), expected_types = c(PARAMCD = "character") ) )
Remove All Temporary Variables Created Within the Current Function Environment
remove_tmp_vars(dataset)
remove_tmp_vars(dataset)
dataset |
The input dataset |
The input dataset with temporary variables removed
library(dplyr, warn.conflicts = FALSE) dm <- tribble( ~DOMAIN, ~STUDYID, ~USUBJID, "DM", "STUDY X", "01-701-1015", "DM", "STUDY X", "01-701-1016", ) dm <- select(dm, USUBJID) tmp_var <- get_new_tmp_var(dm) dm <- mutate(dm, !!tmp_var := NA) ## This function creates two new temporary variables which are removed when calling ## `remove_tmp_vars()`. Note that any temporary variable created outside this ## function is **not** removed do_something <- function(dataset) { tmp_var_1 <- get_new_tmp_var(dm) tmp_var_2 <- get_new_tmp_var(dm) dm %>% mutate(!!tmp_var_1 := NA, !!tmp_var_2 := NA) %>% print() %>% remove_tmp_vars() } do_something(dm)
library(dplyr, warn.conflicts = FALSE) dm <- tribble( ~DOMAIN, ~STUDYID, ~USUBJID, "DM", "STUDY X", "01-701-1015", "DM", "STUDY X", "01-701-1016", ) dm <- select(dm, USUBJID) tmp_var <- get_new_tmp_var(dm) dm <- mutate(dm, !!tmp_var := NA) ## This function creates two new temporary variables which are removed when calling ## `remove_tmp_vars()`. Note that any temporary variable created outside this ## function is **not** removed do_something <- function(dataset) { tmp_var_1 <- get_new_tmp_var(dm) tmp_var_2 <- get_new_tmp_var(dm) dm %>% mutate(!!tmp_var_1 := NA, !!tmp_var_2 := NA) %>% print() %>% remove_tmp_vars() } do_something(dm)
Replace symbols in an expression
replace_symbol_in_expr(expression, target, replace)
replace_symbol_in_expr(expression, target, replace)
expression |
Expression |
target |
Target symbol |
replace |
Replacing symbol |
The expression where every occurrence of the symbol target
is
replaced by replace
Stefan Bundfuss
Helpers for working with Quosures:
add_suffix_to_vars()
,
expr_c()
,
replace_values_by_names()
library(rlang) replace_symbol_in_expr(expr(AVAL), target = AVAL, replace = AVAL.join) replace_symbol_in_expr(expr(AVALC), target = AVAL, replace = AVAL.join) replace_symbol_in_expr(expr(desc(AVAL)), target = AVAL, replace = AVAL.join)
library(rlang) replace_symbol_in_expr(expr(AVAL), target = AVAL, replace = AVAL.join) replace_symbol_in_expr(expr(AVALC), target = AVAL, replace = AVAL.join) replace_symbol_in_expr(expr(desc(AVAL)), target = AVAL, replace = AVAL.join)
Replace Expression Value with Name
replace_values_by_names(expressions)
replace_values_by_names(expressions)
expressions |
A list of expressions |
A list of expressions
Helpers for working with Quosures:
add_suffix_to_vars()
,
expr_c()
,
replace_symbol_in_expr()
library(rlang) replace_values_by_names(exprs(AVAL, ADT = convert_dtc_to_dt(EXSTDTC)))
library(rlang) replace_values_by_names(exprs(AVAL, ADT = convert_dtc_to_dt(EXSTDTC)))
Wrap a String in Single Quotes
squote(x)
squote(x)
x |
A |
A character
vector
Helpers for working with Quotes and Quoting:
backquote()
,
dquote()
,
enumerate()
Suppress certain warnings issued by an expression.
suppress_warning(expr, regexpr)
suppress_warning(expr, regexpr)
expr |
Expression to be executed |
regexpr |
Regular expression matching warnings to suppress |
All warnings which are issued by the expression and match the regular expression are suppressed.
Return value of the expression
Function that provide users with custom warnings
warn_if_incomplete_dtc()
,
warn_if_inconsistent_list()
,
warn_if_invalid_dtc()
,
warn_if_vars_exist()
Contains the acceptable character vector of valid time units
valid_time_units()
valid_time_units()
A character
vector of valid time units
Developer Utility Functions:
%notin%()
,
%or%()
,
arg_name()
,
contains_vars()
,
convert_dtm_to_dtc()
,
extract_vars()
,
filter_if()
,
friendly_type_of()
,
vars2chr()
Turn a List of Expressions into a Character Vector
vars2chr(expressions)
vars2chr(expressions)
expressions |
A |
A character vector
Developer Utility Functions:
%notin%()
,
%or%()
,
arg_name()
,
contains_vars()
,
convert_dtm_to_dtc()
,
extract_vars()
,
filter_if()
,
friendly_type_of()
,
valid_time_units()
library(dplyr, warn.conflicts = FALSE) library(rlang) vars2chr(exprs(USUBJID, AVAL))
library(dplyr, warn.conflicts = FALSE) library(rlang) vars2chr(exprs(USUBJID, AVAL))
Warn if incomplete dtc
warn_if_incomplete_dtc(dtc, n)
warn_if_incomplete_dtc(dtc, n)
dtc |
A |
n |
A non-negative integer |
A warning if dtc
contains any partial dates
Function that provide users with custom warnings
suppress_warning()
,
warn_if_inconsistent_list()
,
warn_if_invalid_dtc()
,
warn_if_vars_exist()
Checks if two list inputs have the same names and same number of elements and issues a warning otherwise.
warn_if_inconsistent_list(base, compare, list_name, i = 2)
warn_if_inconsistent_list(base, compare, list_name, i = 2)
base |
A named list |
compare |
A named list |
list_name |
A string the name of the list |
i |
the index id to compare the 2 lists |
a warning
if the 2 lists have different names or length
Function that provide users with custom warnings
suppress_warning()
,
warn_if_incomplete_dtc()
,
warn_if_invalid_dtc()
,
warn_if_vars_exist()
library(dplyr, warn.conflicts = FALSE) library(rlang) # no warning warn_if_inconsistent_list( base = exprs(DTHDOM = "DM", DTHSEQ = DMSEQ), compare = exprs(DTHDOM = "DM", DTHSEQ = DMSEQ), list_name = "Test" ) # warning warn_if_inconsistent_list( base = exprs(DTHDOM = "DM", DTHSEQ = DMSEQ, DTHVAR = "text"), compare = exprs(DTHDOM = "DM", DTHSEQ = DMSEQ), list_name = "Test" )
library(dplyr, warn.conflicts = FALSE) library(rlang) # no warning warn_if_inconsistent_list( base = exprs(DTHDOM = "DM", DTHSEQ = DMSEQ), compare = exprs(DTHDOM = "DM", DTHSEQ = DMSEQ), list_name = "Test" ) # warning warn_if_inconsistent_list( base = exprs(DTHDOM = "DM", DTHSEQ = DMSEQ, DTHVAR = "text"), compare = exprs(DTHDOM = "DM", DTHSEQ = DMSEQ), list_name = "Test" )
Warn if the vector contains unknown datetime format such as "2003-12-15T-:15:18", "2003-12-15T13:-:19","–12-15","—–T07:15"
warn_if_invalid_dtc(dtc, is_valid = is_valid_dtc(dtc))
warn_if_invalid_dtc(dtc, is_valid = is_valid_dtc(dtc))
dtc |
a character vector containing the dates |
is_valid |
a logical vector indicating whether elements in |
No return value, called for side effects
Function that provide users with custom warnings
suppress_warning()
,
warn_if_incomplete_dtc()
,
warn_if_inconsistent_list()
,
warn_if_vars_exist()
## No warning as `dtc` is a valid date format warn_if_invalid_dtc(dtc = "2021-04-06") ## Issues a warning warn_if_invalid_dtc(dtc = "2021-04-06T-:30:30")
## No warning as `dtc` is a valid date format warn_if_invalid_dtc(dtc = "2021-04-06") ## Issues a warning warn_if_invalid_dtc(dtc = "2021-04-06T-:30:30")
Warn if a variable already exists inside a dataset
warn_if_vars_exist(dataset, vars)
warn_if_vars_exist(dataset, vars)
dataset |
A |
vars |
|
No return value, called for side effects
Function that provide users with custom warnings
suppress_warning()
,
warn_if_incomplete_dtc()
,
warn_if_inconsistent_list()
,
warn_if_invalid_dtc()
library(dplyr, warn.conflicts = FALSE) dm <- tribble( ~USUBJID, ~ARM, "01-701-1015", "Placebo", "01-701-1016", "Placebo", ) ## No warning as `AAGE` doesn't exist in `dm` warn_if_vars_exist(dm, "AAGE") ## Issues a warning warn_if_vars_exist(dm, "ARM")
library(dplyr, warn.conflicts = FALSE) dm <- tribble( ~USUBJID, ~ARM, "01-701-1015", "Placebo", "01-701-1016", "Placebo", ) ## No warning as `AAGE` doesn't exist in `dm` warn_if_vars_exist(dm, "AAGE") ## Issues a warning warn_if_vars_exist(dm, "ARM")
Returns a string describing what kind of object the input is.
what_is_it(x)
what_is_it(x)
x |
Any R object |
A character
description of the type of x
what_is_it("abc") what_is_it(1L) what_is_it(1:10) what_is_it(mtcars)
what_is_it("abc") what_is_it(1L) what_is_it(1:10) what_is_it(mtcars)