For certain composition tasks it is beneficial to get the width of a string
as interpreted by the device that is going to plot it. grid provides this
through construction of a textGrob
and then converting the corresponding
grob width to e.g. cm, but this comes with a huge overhead.
string_widths_dev()
provides direct, vectorised, access to the graphic
device for as high performance as possible.
string_widths_dev(
strings,
family = "",
face = 1,
size = 12,
cex = 1,
unit = "cm"
)
A character vector of strings to measure
The font families to use. Will get recycled
The font faces to use. Will get recycled
The font size to use. Will get recycled
The cex multiplier to use. Will get recycled
The unit to return the width in. Either "cm"
, "inches"
,
"device"
, or "relative"
A numeric vector with the width of each of the strings given in
strings
in the unit given in unit
Other device metrics:
string_metrics_dev()
# Get the widths as measured in cm (default)
string_widths_dev(c('a string', 'an even longer string'))
#> [1] 1.394460 3.936153