flag_if {fgeo.tool} | R Documentation |
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, ...)
## Default S3 method:
flag_if(.data, predicate, condition = warning, msg = NULL, ...)
## S3 method for class '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. |
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)
# 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")
[Package fgeo.tool version 1.2.10 Index]