Skip to contents

Create the default message used when a parameter is found to be the wrong class.

Usage

dis_msg_class(x, class, type, stem, param = "param", call = rlang::caller_env())

Arguments

x

Required object; a parameter argument to test.

class

Required character scalar; the expected class of an object.

type

Required character scalar; one of either "scalar", "vector", or "object".

stem

Required character scalar; the end of the error message containing an example of how to correctly format the input. For example, if you require a numeric scalar, you should include stem = "{.code {param} = 1}.". See the documentation for the cli package to find other formatting examples.

param

Required character scalar; the parameter name. The default matches the argument named for environments used through disputeR.

call

Required environment; the environment in which the function was called. If nesting dis_msg_class() within another function, it is recommended to provide the calling environment to ensure the correct environment is referenced using rlang::caller_env() (default). If there are multiple levels of nesting, the call argument can be used to pass an environment created in the outermost function.

Value

A character string with the default message.

Details

See the vignette on vignette("developing", package = "disputeR") for details about internal validation of arguments for this function. Unlike the core functions, dis_param does not have a fact_check argument. The vignette("developing", package = "disputeR") vignette includes details on how to implement that functionality around dis_param.

Examples

dis_msg_class(x = "test", class = "integer", type = "scalar",
              stem = "{.code {param} = 1}")
#>                                                                                  
#>  "{.arg param} must be a {.cls integer} scalar, not a {.cls {class(x)}} scalar." 
#>                                                                                i 
#> "Provide a {.cls integer} scalar for {.arg param}, such as {.code {param} = 1}."