Generate data frames with wildcards
The wildcard
package (CRAN,
GitHub) is a templating mechanism for data frames in R. Wildcards are placeholders for text, and you can evaluate them to generate new data frames from templates. The technique is similar to expand.grid()
, but more flexible: rather than deal with all possible combinations of your variables, you can choose which rows to expand.
The tutorial vignette on CRAN demonstrates the full functionality, and I have included a taste below.
library(wildcard)
myths <- data.frame(myth = c("Bigfoot", "UFO", "Loch Ness Monster"),
claim = c("various", "day", "day"),
note = c("various", "pictures", "reported day"))
myths
## myth claim note
## 1 Bigfoot various various
## 2 UFO day pictures
## 3 Loch Ness Monster day reported day
wildcard(myths, wildcard = "day", values = c("today", "yesterday"))
## myth claim note
## 1 Bigfoot various various
## 2 UFO today pictures
## 3 UFO yesterday pictures
## 4 Loch Ness Monster today reported today
## 5 Loch Ness Monster yesterday reported yesterday
wildcard(myths, wildcard = "day", values = c("today", "yesterday"), expand = FALSE)
## myth claim note
## 1 Bigfoot various various
## 2 UFO today pictures
## 3 Loch Ness Monster yesterday reported today