Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

string_widths_dev

Get string widths as measured by the current device


Description

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.

Usage

string_widths_dev(
  strings,
  family = "",
  face = 1,
  size = 12,
  cex = 1,
  unit = "cm"
)

Arguments

strings

A character vector of strings to measure

family

The font families to use. Will get recycled

face

The font faces to use. Will get recycled

size

The font size to use. Will get recycled

cex

The cex multiplier to use. Will get recycled

unit

The unit to return the width in. Either "cm", "inches", "device", or "relative"

Value

A numeric vector with the width of each of the strings given in strings in the unit given in unit

See Also

Other device metrics: string_metrics_dev()

Examples

# Get the widths as measured in cm (default)
string_widths_dev(c('a string', 'an even longer string'))

systemfonts

System Native Font Finding

v1.0.2
MIT + file LICENSE
Authors
Thomas Lin Pedersen [aut, cre] (<https://orcid.org/0000-0002-5147-4711>), Jeroen Ooms [aut] (<https://orcid.org/0000-0002-4035-0289>), Devon Govett [aut] (Author of font-manager), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.