wildcard {wildcard} | R Documentation |
Function wildcard
Description
Main function of the package. Evaluate a wildcard
to fill in or expand a data frame.
Copied and modified from remakeGenerator::evaluate()
under GPL-3:
https://github.com/wlandau/remakeGenerator
Usage
wildcard(df, rules = NULL, wildcard = NULL, values = NULL,
expand = TRUE, include = NULL, exclude = NULL)
Arguments
df |
data frame |
rules |
list with names a wildcards and elements as vectors of values to substitute in place of the wildcards. |
wildcard |
character scalar, a wildcard found in a data frame |
values |
vector of values to substitute in place of a wildcard |
expand |
logical, whether to expand the rows of the data frame to
substitute each value for each wildcard in turn.
If |
include |
character vector of columns of |
exclude |
character vector of columns of |
Examples
myths <- data.frame(
myth = c('Bigfoot', 'UFO', 'Loch Ness Monster'),
claim = c('various', 'day', 'day'),
note = c('various', 'pictures', 'reported day'))
wildcard(myths, wildcard = 'day', values = c('today', 'yesterday'))
wildcard(myths, wildcard = 'day', values = c('today', 'yesterday'),
expand = FALSE)
locations <- data.frame(
myth = c('Bigfoot', 'UFO', 'Loch Ness Monster'),
origin = 'where')
rules <- list(
where = c('North America', 'various', 'Scotland'),
UFO = c('spaceship', 'saucer'))
wildcard(locations, rules = rules, expand = c(FALSE, TRUE))
numbers <- data.frame(x = 4, y = 3, z = 4444, w = 4.434)
wildcard(numbers, wildcard = 4, values = 7)
# Inclusion and exclusion
wildcard(myths, wildcard = "day", values = c("today", "yesterday"),
include = "claim")
wildcard(myths, wildcard = "day", values = c("today", "yesterday"),
exclude = c("claim", "note"))
# Wildcards should not also be replacement values.
# Otherwise, the output will be strange
# and will depend on the order of the wildcards.
## Not run:
df <- data.frame(x = "a", y = "b")
rules <- list(a = letters[1:3], b = LETTERS[1:3])
wildcard(df, rules = rules)
## End(Not run)