Description Usage Arguments Details Value Examples
This function calls the error() function to display an error if the
structure of the input is not correct.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  | assert_empty(
  x,
  level = 1,
  msg_level = getOption("msgr.level"),
  msg_types = getOption("msgr.types"),
  log_path = getOption("msgr.log_path")
)
assert_names(
  x,
  names = NULL,
  level = 1,
  msg_level = getOption("msgr.level"),
  msg_types = getOption("msgr.types"),
  log_path = getOption("msgr.log_path")
)
assert_length(
  x,
  n = NULL,
  n_min = NULL,
  n_max = NULL,
  level = 1,
  msg_level = getOption("msgr.level"),
  msg_types = getOption("msgr.types"),
  log_path = getOption("msgr.log_path")
)
 | 
x | 
 (any) The object to test.  | 
level | 
 (integer, optional) The level of the message, from 1 to 10. Default: 1.  | 
msg_level | 
 (integer, optional) The maximum level of messages to output.
Default: set in the option   | 
msg_types | 
 (character, optional) The type to write or display. Must
either NULL or one or more from "INFO", "WARNING" or "ERROR". Default: set
in the option   | 
log_path | 
 (character, optional) The file path to the text log file. If
set to "", then no logs are written. Default: set in the option
  | 
names | 
 (character) The allowed names.  | 
n | 
 (integer, optional) The allowed length.  | 
n_min | 
 (integer, optional) The minimum allowed length.  | 
n_max | 
 (integer, optional) The maximum allowed length.  | 
The following structures can be checked:
assert_empty(): 'x' must be empty or NULL.
assert_names(): 'x' must have names and optionally have the specified
names.
assert_length(): 'x' must have valid length. You can specify the exact
length using n or the minimum and/or maximum length using n_min and
n_max respectively.
If assertion passes then TRUE is returned. This allows you to make
multiple assertions separated by &.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  | ## Not run: 
# No error
assert_empty(NULL)
assert_empty(integer())
# Error
assert_empty(1)
# No error
assert_names(c(name = "Bob", age = 42))
assert_names(c(name = "Bob", age = 42), names = c("name", "age"))
# Error
assert_names(c(name = "Bob", age = 42), names = c("name", "email"))
# No error
assert_length(1:3, n = 3)
assert_length(1:3, n_min = 1)
assert_length(1:3, n_min = 1, n_max = 10)
# Error
assert_length(1:3, n = 1)
assert_length(1:3, n_min = 5)
assert_length(1:3, n_min = 1, n_max = 2)
## End(Not run)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.