These functions extend flag_if()] and detect_if() to work by groups defined with dplyr::group_by().

flag_if_group(.data, name, predicate, condition = warn, msg = NULL)

detect_if_group(.data, name, predicate)

Arguments

.data

A dataframe.

name

String. The name of a column of the dataframe.

predicate

A predicate function, e.g. is_multiple().

condition

A condition function, e.g. rlang::inform() or base::stop().

msg

String to customize the returned message.

Value

  • flag_if_group(): A condition and its first input, invisibly.

  • detect_if_group(): Logical of length 1.

See also

Other functions to check inputs: check_crucial_names(), is_multiple()

Other functions for developers: check_crucial_names(), extract_insensitive(), is_multiple(), nms_try_rename(), rename_matches(), type_ensure()

Examples

tree <- tibble(CensusID = c(1, 2), treeID = c(1, 2))
detect_if_group(tree, "treeID", is_multiple)
#> [1] TRUE
flag_if_group(tree, "treeID", is_multiple)
#> Warning: treeID: Flagged values were detected.

by_censusid <- group_by(tree, CensusID)
detect_if_group(by_censusid, "treeID", is_multiple)
#> [1] FALSE
flag_if_group(by_censusid, "treeID", is_multiple)