pred | R Documentation |
Filter predicate
pred(arg, value)
pred_not(arg, value)
pred_gt(arg, value)
pred_gte(arg, value)
pred_lt(arg, value)
pred_lte(arg, value)
pred_in(arg, value)
pred_notin(arg, value)
pred_na(arg)
pred_notna(arg)
pred_and(...)
pred_or(...)
arg |
(character) The key for the predicate. See "Keys" below. |
value |
(various) The value for the predicate. |
... |
For |
A predicate object. An object of class predicate is a list with the following elements:
arg
: A (list of) character with all arguments in the predicate(s).
value
: A (list of) character with all values in the predicate(s).
type
: A (list of) character with all predicate types, see section
"predicate methods" here below.
expr
: A character: body of a filter expression.
pred*
functions are named for the 'type' of operation they do, inspired by
GBIF occurrence predicates
The following functions take one key and one value and are associated to the following types:
pred
: equals
pred_not
: notEquals
pred_lt
: lessThan
pred_lte
: lessThanOrEquals
pred_gt
: greaterThan
pred_gte
: greaterThanOrEquals
pred_like
: like (NOT IMPLEMENTED YET!)
The following function is only for geospatial queries, and only accepts a WKT string:
pred_within
: within (NOT IMPLEMENTED YET!)
The following functions are only for stating that you do (not) want a key to
be NA
, so only accepts one key:
pred_na
: isNA
pred_notna
: isNotNA
The following two functions accept multiple individual filter predicates, separating them by either "and" or "or":
pred_and
: and
pred_or
: or
The following function is special in that it accepts a single key but many values, stating that you want to search for all the listed values, e.g. one of the locations in: "B_ML_val 05_molenkreek", "B_ML_val 03_De Val" and "B_ML_val 06_Oostpolderkreek"
pred_in
: in
pred_notin
: notIn
Internally, the input to pred*
functions turn into a character string,
which forms the body of a filter expression.
For example:
pred("tags", "boven de stroom")
gives:
$arg [1] "tags" $value [1] "boven de stroom" $type [1] "equals" $expr (tags == "boven de stroom")
pred_gt("latitude", 51.27)
gives, (only expr
element shown):
(latitude > 51.27)
pred_or()
gives:
((tags == "boven de stroom") | (latitude > 51.28))
pred_or()
gives:
((tags == "boven de stroom") & (latitude > 51.28))
Acceptable arguments to the key
parameter are the column names of the
data frame you are applying the filter predicates.
Other filter functions:
apply_filter_predicate()
# One arg one value predicates
pred("scientificName", "Anas platyrhynchos")
pred("tags", "boven de stroom")
pred_gt("latitude", 51.18)
pred_gte("latitude", 51.18)
pred_lt("longitude", 3.95)
pred_lte("longitude", 3.95)
pred_not("locationName", "B_DL_val 3_dikke boom")
# and/or predicates
pred_and(pred_lt("longitude", 3.59), pred_gt("latitude", 51.28))
pred_or(pred_gte("count", 2), pred("vernacular_name", "Norway Rat"))
# Use dates as argument
start_date <- as.Date("2020-06-03", format = "%Y-%m-%d")
end_date <- as.Date("2020-06-10", format = "%Y-%m-%d")
pred_or(pred_gte("start", start_date), pred_lte("end", end_date))
# Use datetimes (POSIXct) as argument
start_date <- lubridate::as_datetime("2020-06-03")
end_date <- lubridate::as_datetime("2020-06-10")
pred_or(pred_gte("start", start_date), pred_lte("end", end_date))
# One arg multiple values predicates
locations <- c("B_ML_val 03_De Val", "B_ML_val 05_molenkreek")
pred_in("location_name", locations)
pred_notin("location_name", locations)
start_dates <- lubridate::as_datetime(c("2020-06-03 20:10:18", "2020-06-03 20:04:33"))
pred_in("start", start_dates)
pred_notin("start", start_dates)
# One arg, no value predicates
pred_na("scientificName")
pred_notna("scientificName")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.