str_englue | R Documentation |
str_englue()
helps you solve the labeling problem during plotting. For example, any value wrapped in { }
will be inserted into the string and it can also understands embracing, {{ }}
, which automatically inserts a given variable name.
str_englue(x, env, error_call, error_arg)
x |
A string to interpolate with glue operators. |
env |
User environment where the interpolation data lives in
case you're wrapping |
error_call |
The execution environment of a currently
running function, e.g. |
error_arg |
An argument name as a string. This argument will be mentioned in error messages as the input that is at the origin of a problem. |
rlang::englue()
library(ggplot2)
histogram_plot <- function(df, var, binwidth) {
ggplot(df, aes(x = {{ var }})) +
geom_histogram(binwidth = binwidth) +
labs(title = str_englue("A histogram of {{var}} with binwidth {binwidth}"))
}
histogram_plot(iris, Sepal.Length, binwidth = 0.1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.