Description Usage Arguments Value Specifying replacement values See Also Examples
This function replicates pattern objects, replacing placeholder keywords in each iteration with values from the provided data. This allows efficiently creating R Markdown documents with many repeating pieces which may shift alongside the underlying data.
1 |
data |
Input dataframe to pull replacement values from. Accepts either vector or dataframe inputs. |
pattern |
The base pattern, as either an atomic vector (which will be
recycled for every value in your data) or a vector of the same length as
your data (which will be applied element-wise to your data, so that
|
... |
Values indicating what placeholders in the pattern should be replaced – see "Specifying replacement values" below for more. |
strip.whitespace |
A boolean (TRUE/FALSE) value indicating if whitespace should be removed from the replacement variable. Toggle this on if you're using the variable in chunk labels or similar places. |
Returns a character vector of the pattern with placeholders replaced by variables.
heddle
can accept multiple different values for ...
, depending
on how you call it.
If data
is a vector (which is the case when either
calling heddle
on a vector directly, or using it in a
mutate
) call, ...
should be unnamed strings
matching the values to be replaced. If any argument passed to ...
isn't found in the pattern, a warning will be raised – use NA
to
replicate patterns without replacing any values.
If data
is a dataframe (which is the case both when calling
heddle
on a dataframe directly or using it in combination with
nest
and map
),
...
should be a set of name = variable
pairs, with the name matching the keyword to be replaced by that variable.
Names should be quoted, variable names don't need to be. As with vectors,
if any argument passed to ...
isn't found in the pattern, a warning
will be raised.
Other manipulation functions:
create_yaml_header()
,
make_template()
,
provide_parameters()
,
use_parameters()
1 2 3 4 5 6 7 8 9 10 11 12 | # When passed a vector, heddle replaces all placeholders passed to ...
# with each value
spList <- unique(iris$Species)
heddle(spList, "SPECIES CODE GWAR ", "GWAR")
heddle(spList, "SPECIES CODE GWAR ", "GWAR", "CODE")
heddle("test string", "pattern tk", "tk", strip.whitespace = TRUE)
# When passed a dataframe, heddle uses "Name" = Variable syntax to determine
# which values should replace which placeholders
spList <- data.frame(Species = c(unique(iris$Species), "test string"))
heddle(spList, "SPECIES CODE GWAR ", "GWAR" = Species)
heddle(spList, "SPECIES CODE GWAR ", "GWAR" = Species, "CODE" = Species)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.