Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I cannot import fonts using font_import

Tags:

r

fonts

ggplot2

I am trying to import fonts for ggplot2 graphs as in described here.

When I try do to so piece by piece with this code :

font_import(pattern = "Arial.ttf")
y

I get this error :

canning ttf files in C:\windows\Fonts ...
Extracting .afm files from .ttf files...
Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : 
  arguments imply differing number of rows: 0, 1

I have checked that I have indeed the Arial font : enter image description here

What is my problem

like image 803
Anthony Martin Avatar asked Sep 19 '25 00:09

Anthony Martin


1 Answers

I was having the same problem, i.e. trying to import a font (Zallman Caps) using font_import() and receiving the same error:

"Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : 
   arguments imply differing number of rows: 0, 1"

After a lot of trial and error, I finally found a solution that worked for me and perhaps it will for you, as well.

Even though I could see the Zallman Caps font in my Windows Fonts folder and verified that it worked in Word, neither font_import() nor list.files() could find it there. I managed to import the font by entering the following code:

font_import(path = "C:/Users/*insert your user name*/AppData/Local/Microsoft/Windows/Fonts", pattern = ".TTF")

I have no idea why it isn't visible to R in the main fonts directory, when I can clearly see it in Windows file explorer, but at least I managed to import the font using this workaround.

like image 118
Jenny Hansen Avatar answered Sep 20 '25 12:09

Jenny Hansen