fgeo.tool (version 1.2.5)

flag_if_group: Detect and flag based on a predicate applied to a variable by groups.

Description

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

Usage

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

Run this code
# NOT RUN {
tree <- tibble(CensusID = c(1, 2), treeID = c(1, 2))
detect_if_group(tree, "treeID", is_multiple)
flag_if_group(tree, "treeID", is_multiple)

by_censusid <- group_by(tree, CensusID)
detect_if_group(by_censusid, "treeID", is_multiple)
flag_if_group(by_censusid, "treeID", is_multiple)
# }

Run the code above in your browser using DataLab