19
votes

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

4
Can you find the file? Does Garamond.ttf exist in your Fonts folder?Gregor Thomas
Hi, I can find the file in the fonts-folder ("~Library/Fonts/"). And I can find the other fonts imported by the font_import() function. Some other fonts in the catalog are also being excluded by the import function. Also tried to re-install the font. But it doesn't seem to help. The font works perfectly fine with other softwares.Fredrik
It's not the folder I'm asking about. I understand that your font folder exists. I would like you to confirm that a file called Garamond.ttf is in your fonts folder. Perhaps you have it installed as an OTF, or perhaps you don't have it all, or perhaps it's somewhere else...Gregor Thomas
@Fredrik You can find possible filenames at this link. Maybe it will help.NCC1701

4 Answers

11
votes
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.

6
votes

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.

6
votes

You can also import fonts in a specific folder with extrafont:

library(extrafont)
font_import(paths = c("c:/path/to/folder/with/fonts/", prompt = F)

This way if you have a copy of Garamond (or any other font) that's not installed in the system font library, you can still use it.

0
votes

I had this same error message and this is why. If the font.ttf file is not in the ~Library/Fonts directory, then font_import(pattern="font.ttf") will not work. Look in the ~Library/Fonts directory and see that the file is actually there in the format you expect. If not then just download it and put it there. Be sure to call the file exactly as it appears in the ~Library/Fonts directory. Cheers