Skip to contents

Subset system fonts for review, to organize fonts available to systemfonts

Usage

subset_systemfonts(
  ...,
  fonts_df = systemfonts::system_fonts(),
  do_plot = FALSE,
  return_type = c("data.frame"),
  trim_path = TRUE,
  do_sort = TRUE,
  byCols = c("family", "italic", "weight", "style", "width", "name"),
  remove_problem_fonts = TRUE
)

Arguments

...

additional arguments are passed to subset() to subset the resulting table accordingly. This argument is first to avoid matching other named arguments below.

fonts_df

data.frame full set of fonts, default uses systemfonts::system_fonts() to include all fonts recognized by systemfonts.

do_plot

logical whether to plot the search results using marquee, default FALSE.

return_type

character string with return class, default is 'data.frame' which converts the tibble output to data.frame for convenience.

trim_path

logical whether to trim the font file path, default TRUE removes the folder by calling basename().

do_sort

logical whether to sort output, using 'byCols'.

byCols

character columns used when do_sort==TRUE.

remove_problem_fonts

logical default TRUE, whether to check for errors accessing each font family by calling systemfonts::font_info().

Value

data.frame with font information derived from systemfonts::system_fonts() and subset according to '...'.

Details

This function provides a convenient method to subset fonts recognized by systemfonts::system_fonts(), while also sorting and filtering out "problem fonts". The argument do_plot=TRUE will visualize the resulting fonts using marquee::marquee_grob().

Note that there are some "problem fonts" which are not recognized by the Freetype API used by systemfonts, which appear to arise from newer font file formats released on MacOS which are not yet recognized by Freetype. Using one of these fonts may cause R crash, therefore some steps were taken to avoid this possibility:

  • The output will include one new column "check" with integer number of valid associated font files, usually 1 for valid, and 0 for no valid files.

  • The argument remove_problem_fonts=TRUE removes any fonts with 0, thereby helping to avoid crashing the R session.

  • The function check_systemfonts_family() will check one or more font family values, returning the integer number of valid font files.

Examples

subset_systemfonts(grepl("(Arial(.*Narrow|)|Helvetica)$", family))
#>                            path index                   name       family
#> 4                     Arial.ttf     0                ArialMT        Arial
#> 10               Arial Bold.ttf     0           Arial-BoldMT        Arial
#> 9              Arial Italic.ttf     0         Arial-ItalicMT        Arial
#> 1         Arial Bold Italic.ttf     0     Arial-BoldItalicMT        Arial
#> 11             Arial Narrow.ttf     0            ArialNarrow Arial Narrow
#> 2         Arial Narrow Bold.ttf     0       ArialNarrow-Bold Arial Narrow
#> 5       Arial Narrow Italic.ttf     0     ArialNarrow-Italic Arial Narrow
#> 14 Arial Narrow Bold Italic.ttf     0 ArialNarrow-BoldItalic Arial Narrow
#> 6                 Helvetica.ttc     4        Helvetica-Light    Helvetica
#> 8                 Helvetica.ttc     0              Helvetica    Helvetica
#> 3                 Helvetica.ttc     1         Helvetica-Bold    Helvetica
#> 12                Helvetica.ttc     5 Helvetica-LightOblique    Helvetica
#> 13                Helvetica.ttc     2      Helvetica-Oblique    Helvetica
#> 7                 Helvetica.ttc     3  Helvetica-BoldOblique    Helvetica
#>            style weight  width italic monospace check
#> 4        Regular normal normal  FALSE     FALSE     1
#> 10          Bold   bold normal  FALSE     FALSE     1
#> 9         Italic normal normal   TRUE     FALSE     1
#> 1    Bold Italic   bold normal   TRUE     FALSE     1
#> 11       Regular normal normal  FALSE     FALSE     1
#> 2           Bold   bold normal  FALSE     FALSE     1
#> 5         Italic normal normal   TRUE     FALSE     1
#> 14   Bold Italic   bold normal   TRUE     FALSE     1
#> 6          Light  light normal  FALSE     FALSE     1
#> 8        Regular normal normal  FALSE     FALSE     1
#> 3           Bold   bold normal  FALSE     FALSE     1
#> 12 Light Oblique  light normal   TRUE     FALSE     1
#> 13       Oblique normal normal   TRUE     FALSE     1
#> 7   Bold Oblique   bold normal   TRUE     FALSE     1
subset_systemfonts(grepl("(Arial(.*Narrow|)|Helvetica.*)$", family), do_plot=TRUE)

#>                            path index                           name
#> 13                    Arial.ttf     0                        ArialMT
#> 23               Arial Bold.ttf     0                   Arial-BoldMT
#> 22             Arial Italic.ttf     0                 Arial-ItalicMT
#> 1         Arial Bold Italic.ttf     0             Arial-BoldItalicMT
#> 24             Arial Narrow.ttf     0                    ArialNarrow
#> 5         Arial Narrow Bold.ttf     0               ArialNarrow-Bold
#> 14      Arial Narrow Italic.ttf     0             ArialNarrow-Italic
#> 28 Arial Narrow Bold Italic.ttf     0         ArialNarrow-BoldItalic
#> 15                Helvetica.ttc     4                Helvetica-Light
#> 20                Helvetica.ttc     0                      Helvetica
#> 9                 Helvetica.ttc     1                 Helvetica-Bold
#> 25                Helvetica.ttc     5         Helvetica-LightOblique
#> 26                Helvetica.ttc     2              Helvetica-Oblique
#> 17                Helvetica.ttc     3          Helvetica-BoldOblique
#> 27            HelveticaNeue.ttc     5       HelveticaNeue-UltraLight
#> 4             HelveticaNeue.ttc    12             HelveticaNeue-Thin
#> 18            HelveticaNeue.ttc     7            HelveticaNeue-Light
#> 19            HelveticaNeue.ttc     0                  HelveticaNeue
#> 11            HelveticaNeue.ttc    10           HelveticaNeue-Medium
#> 3             HelveticaNeue.ttc     1             HelveticaNeue-Bold
#> 2             HelveticaNeue.ttc     4    HelveticaNeue-CondensedBold
#> 16            HelveticaNeue.ttc     9   HelveticaNeue-CondensedBlack
#> 21            HelveticaNeue.ttc     6 HelveticaNeue-UltraLightItalic
#> 8             HelveticaNeue.ttc    13       HelveticaNeue-ThinItalic
#> 7             HelveticaNeue.ttc     8      HelveticaNeue-LightItalic
#> 6             HelveticaNeue.ttc     2           HelveticaNeue-Italic
#> 10            HelveticaNeue.ttc    11     HelveticaNeue-MediumItalic
#> 12            HelveticaNeue.ttc     3       HelveticaNeue-BoldItalic
#>            family             style     weight         width italic monospace
#> 13          Arial           Regular     normal        normal  FALSE     FALSE
#> 23          Arial              Bold       bold        normal  FALSE     FALSE
#> 22          Arial            Italic     normal        normal   TRUE     FALSE
#> 1           Arial       Bold Italic       bold        normal   TRUE     FALSE
#> 24   Arial Narrow           Regular     normal        normal  FALSE     FALSE
#> 5    Arial Narrow              Bold       bold        normal  FALSE     FALSE
#> 14   Arial Narrow            Italic     normal        normal   TRUE     FALSE
#> 28   Arial Narrow       Bold Italic       bold        normal   TRUE     FALSE
#> 15      Helvetica             Light      light        normal  FALSE     FALSE
#> 20      Helvetica           Regular     normal        normal  FALSE     FALSE
#> 9       Helvetica              Bold       bold        normal  FALSE     FALSE
#> 25      Helvetica     Light Oblique      light        normal   TRUE     FALSE
#> 26      Helvetica           Oblique     normal        normal   TRUE     FALSE
#> 17      Helvetica      Bold Oblique       bold        normal   TRUE     FALSE
#> 27 Helvetica Neue        UltraLight       thin        normal  FALSE     FALSE
#> 4  Helvetica Neue              Thin ultralight        normal  FALSE     FALSE
#> 18 Helvetica Neue             Light      light        normal  FALSE     FALSE
#> 19 Helvetica Neue           Regular     normal        normal  FALSE     FALSE
#> 11 Helvetica Neue            Medium     medium        normal  FALSE     FALSE
#> 3  Helvetica Neue              Bold       bold        normal  FALSE     FALSE
#> 2  Helvetica Neue    Condensed Bold       bold semicondensed  FALSE     FALSE
#> 16 Helvetica Neue   Condensed Black      heavy semicondensed  FALSE     FALSE
#> 21 Helvetica Neue UltraLight Italic       thin        normal   TRUE     FALSE
#> 8  Helvetica Neue       Thin Italic ultralight        normal   TRUE     FALSE
#> 7  Helvetica Neue      Light Italic      light        normal   TRUE     FALSE
#> 6  Helvetica Neue            Italic     normal        normal   TRUE     FALSE
#> 10 Helvetica Neue     Medium Italic     medium        normal   TRUE     FALSE
#> 12 Helvetica Neue       Bold Italic       bold        normal   TRUE     FALSE
#>    check
#> 13     1
#> 23     1
#> 22     1
#> 1      1
#> 24     1
#> 5      1
#> 14     1
#> 28     1
#> 15     1
#> 20     1
#> 9      1
#> 25     1
#> 26     1
#> 17     1
#> 27     1
#> 4      1
#> 18     1
#> 19     1
#> 11     1
#> 3      1
#> 2      1
#> 16     1
#> 21     1
#> 8      1
#> 7      1
#> 6      1
#> 10     1
#> 12     1
subset_systemfonts(grepl("Helvetica Neue", family), do_plot=FALSE)
#>                 path index                           name         family
#> 14 HelveticaNeue.ttc     5       HelveticaNeue-UltraLight Helvetica Neue
#> 3  HelveticaNeue.ttc    12             HelveticaNeue-Thin Helvetica Neue
#> 11 HelveticaNeue.ttc     7            HelveticaNeue-Light Helvetica Neue
#> 12 HelveticaNeue.ttc     0                  HelveticaNeue Helvetica Neue
#> 8  HelveticaNeue.ttc    10           HelveticaNeue-Medium Helvetica Neue
#> 2  HelveticaNeue.ttc     1             HelveticaNeue-Bold Helvetica Neue
#> 1  HelveticaNeue.ttc     4    HelveticaNeue-CondensedBold Helvetica Neue
#> 10 HelveticaNeue.ttc     9   HelveticaNeue-CondensedBlack Helvetica Neue
#> 13 HelveticaNeue.ttc     6 HelveticaNeue-UltraLightItalic Helvetica Neue
#> 6  HelveticaNeue.ttc    13       HelveticaNeue-ThinItalic Helvetica Neue
#> 5  HelveticaNeue.ttc     8      HelveticaNeue-LightItalic Helvetica Neue
#> 4  HelveticaNeue.ttc     2           HelveticaNeue-Italic Helvetica Neue
#> 7  HelveticaNeue.ttc    11     HelveticaNeue-MediumItalic Helvetica Neue
#> 9  HelveticaNeue.ttc     3       HelveticaNeue-BoldItalic Helvetica Neue
#>                style     weight         width italic monospace check
#> 14        UltraLight       thin        normal  FALSE     FALSE     1
#> 3               Thin ultralight        normal  FALSE     FALSE     1
#> 11             Light      light        normal  FALSE     FALSE     1
#> 12           Regular     normal        normal  FALSE     FALSE     1
#> 8             Medium     medium        normal  FALSE     FALSE     1
#> 2               Bold       bold        normal  FALSE     FALSE     1
#> 1     Condensed Bold       bold semicondensed  FALSE     FALSE     1
#> 10   Condensed Black      heavy semicondensed  FALSE     FALSE     1
#> 13 UltraLight Italic       thin        normal   TRUE     FALSE     1
#> 6        Thin Italic ultralight        normal   TRUE     FALSE     1
#> 5       Light Italic      light        normal   TRUE     FALSE     1
#> 4             Italic     normal        normal   TRUE     FALSE     1
#> 7      Medium Italic     medium        normal   TRUE     FALSE     1
#> 9        Bold Italic       bold        normal   TRUE     FALSE     1

subset_systemfonts(grepl("serif", ignore.case=TRUE, name), do_plot=TRUE)

#>                        path index                        name
#> 8  Microsoft Sans Serif.ttf     0          MicrosoftSansSerif
#> 13     NotoSerifMyanmar.ttc     3 NotoSerifMyanmar-ExtraLight
#> 16     NotoSerifMyanmar.ttc     8       NotoSerifMyanmar-Thin
#> 7      NotoSerifMyanmar.ttc     4      NotoSerifMyanmar-Light
#> 2      NotoSerifMyanmar.ttc     6    NotoSerifMyanmar-Regular
#> 14     NotoSerifMyanmar.ttc     5     NotoSerifMyanmar-Medium
#> 3      NotoSerifMyanmar.ttc     7   NotoSerifMyanmar-SemiBold
#> 1      NotoSerifMyanmar.ttc     1       NotoSerifMyanmar-Bold
#> 11     NotoSerifMyanmar.ttc     2  NotoSerifMyanmar-ExtraBold
#> 10     NotoSerifMyanmar.ttc     0      NotoSerifMyanmar-Black
#> 9               PTSerif.ttc     0             PTSerif-Regular
#> 4               PTSerif.ttc     3                PTSerif-Bold
#> 15              PTSerif.ttc     1              PTSerif-Italic
#> 5               PTSerif.ttc     2          PTSerif-BoldItalic
#> 6        PTSerifCaption.ttc     0             PTSerif-Caption
#> 12       PTSerifCaption.ttc     1       PTSerif-CaptionItalic
#>                  family       style     weight  width italic monospace check
#> 8  Microsoft Sans Serif     Regular     normal normal  FALSE     FALSE     1
#> 13   Noto Serif Myanmar  ExtraLight       thin normal  FALSE     FALSE     1
#> 16   Noto Serif Myanmar        Thin ultralight normal  FALSE     FALSE     1
#> 7    Noto Serif Myanmar       Light      light normal  FALSE     FALSE     1
#> 2    Noto Serif Myanmar     Regular     normal normal  FALSE     FALSE     1
#> 14   Noto Serif Myanmar      Medium     medium normal  FALSE     FALSE     1
#> 3    Noto Serif Myanmar    SemiBold   semibold normal  FALSE     FALSE     1
#> 1    Noto Serif Myanmar        Bold       bold normal  FALSE     FALSE     1
#> 11   Noto Serif Myanmar   ExtraBold  ultrabold normal  FALSE     FALSE     1
#> 10   Noto Serif Myanmar       Black      heavy normal  FALSE     FALSE     1
#> 9              PT Serif     Regular     normal normal  FALSE     FALSE     1
#> 4              PT Serif        Bold       bold normal  FALSE     FALSE     1
#> 15             PT Serif      Italic     normal normal   TRUE     FALSE     1
#> 5              PT Serif Bold Italic       bold normal   TRUE     FALSE     1
#> 6      PT Serif Caption     Regular     normal normal  FALSE     FALSE     1
#> 12     PT Serif Caption      Italic     normal normal   TRUE     FALSE     1