22

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

lmo
  • 37,904
  • 9
  • 56
  • 69
Fredrik
  • 221
  • 1
  • 2
  • 3
  • 2
    Can you find the file? Does `Garamond.ttf` exist in your Fonts folder? – Gregor Thomas Apr 28 '16 at 20:12
  • 1
    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 Apr 29 '16 at 07:40
  • 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 Apr 29 '16 at 15:02
  • @Fredrik You can find possible filenames at this [link](https://learn.microsoft.com/en-us/typography/font-list/garamond). Maybe it will help. – NCC1701 May 14 '21 at 23:43

5 Answers5

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

  • 2
    `C:\Windows\Fonts` is a virtual folder and entries have no Properties to view. Perhaps you may have better luck with `C:\Windows\WinSxS`? – Steve Pitchers Nov 08 '17 at 18:02
6

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.

alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
  • Hi, that was my first try. font_import() seem to import all fonts. Not all fonts located in the "~Library/fonts/" folder are imported correctly when using this function. As an example: "Verdana.ttf" works perfectly fine, but not "Garamond.ttf". That's why I tried to specify the exact file-name. – Fredrik Apr 29 '16 at 07:39
  • Where are they getting imported to? Is there a way to check? – wolfsatthedoor Oct 23 '22 at 22:37
6

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.

Max Masnick
  • 3,277
  • 2
  • 27
  • 28
  • I had downloaded and extracted from the zipped folder a new font family (Roboto). When I installed the font family it showed in my `C:\Windows\Fonts`. I used the command line prompt to list that directory's contents in chronological order to get the exact `.ttf` name to follow the suggested post by @Dailer Fonticiella Morell, however it was not listed and I have no idea why. Pointing `font_import` to the unzipped folder in my downloads was the only thing that worked. When I did this it imported it with the `.ttf` name I expected. So I'm not sure what's going on with the Fonts folder. – LMc Dec 30 '20 at 23:13
  • this is missing a closing bracket on the character vector. But even with that, it doesn't work for me – Mark Jun 28 '23 at 23:43
1

See: How can I resolve the "No Font Name" issue when importing fonts into R using extrafont?

There is some serious bug in extrafont. Use the new package showtext instead. It works like a charm. (https://cran.rstudio.com/web/packages/showtext/vignettes/introduction.html)

ap21
  • 2,372
  • 3
  • 16
  • 32
0

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