This function returns a condition (error, warning, or message) and its first argument, invisibly. It is a generic. If the first input is a vector, it evaluates it directly; if it is is a dataframe, it evaluates a given column.

flag_if(.data, ...)

# S3 method for default
flag_if(.data, predicate, condition = warning, msg = NULL, ...)

# S3 method for data.frame
flag_if(.data, name, predicate, condition = warning, msg = NULL, ...)

Arguments

.data

Vector.

...

Other arguments passed to methods.

predicate

A predicate function.

condition

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

msg

String. An optional custom message.

name

String. The name of a column of a dataframe.

Value

A condition (and .data invisibly).

See also

Other functions for internal use in other fgeo packages: guess_plotdim(), is_multiple()

Examples

# WITH VECTORS
dupl <- c(1, 1)
flag_if(dupl, is_duplicated)
#> Warning: Flagged values were detected.
# Silent
flag_if(dupl, is_multiple)

mult <- c(1, 2)
flag_if(mult, is_multiple, message, "Custom")
#> Custom
# Silent
flag_if(mult, is_duplicated)

# Both silent
flag_if(c(1, NA), is_multiple)
flag_if(c(1, NA), is_duplicated)

# WITH DATAFRAMES
.df <- data.frame(a = 1:3, b = 1, stringsAsFactors = FALSE)
flag_if(.df, "b", is_multiple)
flag_if(.df, "a", is_multiple)
#> Warning: a: Flagged values were detected.
flag_if(.df, "a", is_multiple, message, "Custom")
#> Custom