Learn R Programming

fgeo.tool (version 1.2.9)

flag_if: Flag if a vector or dataframe-column meets a condition.

Description

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.

Usage

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, ...)

Value

A condition (and .data invisibly).

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.

See Also

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

Examples

Run this code
# WITH VECTORS
dupl <- c(1, 1)
flag_if(dupl, is_duplicated)
# Silent
flag_if(dupl, is_multiple)

mult <- c(1, 2)
flag_if(mult, is_multiple, message, "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)
flag_if(.df, "a", is_multiple, message, "Custom")

Run the code above in your browser using DataLab