These functions take a vector of arguments and pass on the
ith item of the vector to an
ith call of a function. The
elem_list_text
and elem_list_rect
are convenience functions for
constructing lists of element_text()
and
element_rect()
theme elements.
Usage
distribute_args(..., .fun = element_text, .cull = TRUE)
elem_list_text(...)
elem_list_rect(...)
Arguments
- ...
Vectorised arguments to pass on to functions.
- .fun
A function to distribute arguments to.
- .cull
A
logical(1)
determining if unknown arguments are being culled.
Details
NA
s and NULL
s will be silently dropped. If you want to pass on a
transparent fill
or colour
argument, you should use the more verbose
character "transparent"
instead. However, you can use a NA
to
indicate that it's argument should not be passed to a function in that
position.
Note
Whereas the distribute_args
function might seem amenable for
off-label uses elsewhere (besides constructing lists of theme elements), it
is not intended as such. For example, because valid arguments will be
deduced from the formals of a function, using certain functions can be
troublesome. For example, the distribute_args
function does not properly
recognise the utility of a ...
argument in a function that it is supposed
to distribute arguments to. This can be a problem for object-oriented
functions: if the methods contain more arguments than the generic itself,
these extra arguments will be silently dropped.
See also
The element_text()
and
element_rect()
theme elements for a
description of their arguments.
Examples
# Providing arguments for `element_rect()`
elem_list_rect(
# The first element_rect will have linetype 1, the second gets 3
linetype = c(1, 3),
# If an argument doesn't exist, it will be silently dropped
nonsense_argument = c("I", "will", "be", "filtered", "out")
)
#> [[1]]
#> List of 5
#> $ fill : NULL
#> $ colour : NULL
#> $ linewidth : NULL
#> $ linetype : num 1
#> $ inherit.blank: logi FALSE
#> - attr(*, "class")= chr [1:2] "element_rect" "element"
#>
#> [[2]]
#> List of 5
#> $ fill : NULL
#> $ colour : NULL
#> $ linewidth : NULL
#> $ linetype : num 3
#> $ inherit.blank: logi FALSE
#> - attr(*, "class")= chr [1:2] "element_rect" "element"
#>
# Providing arguments for `element_text()`
elem_list_text(
# `NA`s will be skipped
family = c("mono", NA, "sans"),
# Providing a list of more complex arguments. `NULL` will be skipped too.
margin = list(NULL, margin(t = 5))
)
#> [[1]]
#> List of 11
#> $ family : chr "mono"
#> $ face : NULL
#> $ colour : NULL
#> $ size : NULL
#> $ hjust : NULL
#> $ vjust : NULL
#> $ angle : NULL
#> $ lineheight : NULL
#> $ margin : NULL
#> $ debug : NULL
#> $ inherit.blank: logi FALSE
#> - attr(*, "class")= chr [1:2] "element_text" "element"
#>
#> [[2]]
#> List of 11
#> $ family : NULL
#> $ face : NULL
#> $ colour : NULL
#> $ size : NULL
#> $ hjust : NULL
#> $ vjust : NULL
#> $ angle : NULL
#> $ lineheight : NULL
#> $ margin : 'margin' num [1:4] 5points 0points 0points 0points
#> ..- attr(*, "unit")= int 8
#> $ debug : NULL
#> $ inherit.blank: logi FALSE
#> - attr(*, "class")= chr [1:2] "element_text" "element"
#>
#> [[3]]
#> List of 11
#> $ family : chr "sans"
#> $ face : NULL
#> $ colour : NULL
#> $ size : NULL
#> $ hjust : NULL
#> $ vjust : NULL
#> $ angle : NULL
#> $ lineheight : NULL
#> $ margin : NULL
#> $ debug : NULL
#> $ inherit.blank: logi FALSE
#> - attr(*, "class")= chr [1:2] "element_text" "element"
#>
# Providing arguments to other functions
distribute_args(
lineend = c("round", "butt", "square"),
# If you want to pass a vector instead of a scalar, you can use a list
colour = list(c("blue", "red"), "green"),
.fun = element_line
)
#> [[1]]
#> List of 6
#> $ colour : chr [1:2] "blue" "red"
#> $ linewidth : NULL
#> $ linetype : NULL
#> $ lineend : chr "round"
#> $ arrow : logi FALSE
#> $ inherit.blank: logi FALSE
#> - attr(*, "class")= chr [1:2] "element_line" "element"
#>
#> [[2]]
#> List of 6
#> $ colour : chr "green"
#> $ linewidth : NULL
#> $ linetype : NULL
#> $ lineend : chr "butt"
#> $ arrow : logi FALSE
#> $ inherit.blank: logi FALSE
#> - attr(*, "class")= chr [1:2] "element_line" "element"
#>
#> [[3]]
#> List of 6
#> $ colour : NULL
#> $ linewidth : NULL
#> $ linetype : NULL
#> $ lineend : chr "square"
#> $ arrow : logi FALSE
#> $ inherit.blank: logi FALSE
#> - attr(*, "class")= chr [1:2] "element_line" "element"
#>