wildcard: Function 'wildcard'

Description Usage Arguments Examples

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

1
2
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 FALSE, no new rows will be added to df when the values are substituted in place of wildcards. Can be a vector of length length(rules) if using the rules argument.

include

character vector of columns of df to be included in the wildcard evaluation. The values will replace the wildcards in these columns but not in any of the other colums. All columns are included by default. You may use include or exclude (or neither), but not both.

exclude

character vector of columns of df to be EXCLUDED from the wildcard evaluation. The values will NOT replace the wildcards in any of these columns, but wildcard evaluation will occur in all the other columns. By default, no columns are excluded (all columns are used for wildcard evaluation). You may use include or exclude (or neither), but not both.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)

wlandau/wildcard documentation built on May 21, 2019, 2:23 p.m.