Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import font into R using extrafont package

Tags:

I'm trying to import Garamond into R using the extrafont package. I am able to successfully import other fonts when using the unspecified font_import() function directed towards the font location folder, but I'm missing out several fonts located in that folder. Any suggestion why only some fonts are imported and others not?

I've tried the

font_import(pattern = "Garamond.ttf")
ttf_import(pattern = "Garamond.ttf")

with the following error message:

Scanning ttf files in /Library/Fonts/, /System/Library/Fonts, ~/Library/Fonts/ ... Extracting .afm files from .ttf files... Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : arguments imply differing number of rows: 0, 1

like image 844
Fredrik Avatar asked Apr 28 '16 19:04

Fredrik


People also ask

What is extrafont in R?

The extrafont package makes it easier to use fonts other than the basic PostScript fonts that R uses. Fonts that are imported into extrafont can be used with PDF or PostScript output files. On Windows, extrafont will also make system fonts available for bitmap output.

How to add custom fonts in R?

However, it is possible to add custom fonts in R with the extrafont or the showtext packages. The extrafont package allows adding True Font Type ( .ttf) fonts to R easily. Before loading the package, we recommend you to install all the fonts you want in your system.

What is an extrafont package?

Extrafont supports font packages, which contain fonts that are packaged in a particular way so that they can be imported into extrafont. These fonts are installed as R packages; they are not installed for the computer operating system. Fonts that are installed this way will be available only for PDF or PostScript output.

What are the integrated fonts in R?

The integrated fonts in R are sans (Arial), serif (Times New Roman), mono (Courier) and symbol (Standard Symbols L). However, it is possible to add custom fonts in R with the extrafont or the showtext packages.


2 Answers

font_import(pattern = 'GARAIT')

In order to know the correct name, right click in your installed TTF font, select properties an use the name showed at the top of the "General" tab.

like image 91
Dailer Fonticiella Morell Avatar answered Sep 24 '22 00:09

Dailer Fonticiella Morell


Just import them all, perhaps? It takes a while to run.

install.packages("extrafont")
library(extrafont)
font_import()

I've used Garamond, one of my favorite fonts, before.

like image 41
Alex W Avatar answered Sep 25 '22 00:09

Alex W