abichat
abichat

Reputation: 2426

Error in font_import while installing xkcd font

I was trying to install the xkcd font for R on my Mac following the instructions in vignette("xkcd-intro")

> download.file("http://simonsoftware.se/other/xkcd.ttf", dest="xkcd.ttf", mode="wb")
essai de l'URL 'http://simonsoftware.se/other/xkcd.ttf'
Content type 'application/x-font-ttf' length 12712 bytes (12 KB)
==================================================
downloaded 12 KB

> system("mkdir ~/.fonts")
> system("cp xkcd.ttf  ~/.fonts")

Until here, all seems to be ok be I have an error with the following call to font import:

> font_import(pattern = "[X/x]kcd", prompt=FALSE)
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

How can I fix that? Is there another way to install these font?

I already looked at questions here about R and xkcd font like Not able to install xkcd fonts and xkcd style graph - error with registered fonts but it's not the same problem.

Upvotes: 1

Views: 1297

Answers (2)

markhogue
markhogue

Reputation: 1179

Here's what worked for me. I noticed that the fonts were being searched for in the wrong directory. In my case, there was the message,

    Scanning ttf files in C:\Windows\Fonts ...

So, I changed the command to look in my working directory...

Old version

        font_import(pattern = "[X/x]kcd", prompt=FALSE)

New version

        font_import(paths = getwd(), pattern = "[X/x]kcd", prompt=FALSE)

Success! Hope it works for you too.

Upvotes: 4

abichat
abichat

Reputation: 2426

The auto-detected path in font_import was wrong. To fix it:

font_import(path = "~/.fonts", pattern = "[X/x]kcd", prompt=FALSE)

Upvotes: 1

Related Questions