首页 > 解决方案 > 我无法使用 font_import 导入字体

问题描述

我正在尝试为 ggplot2 图形导入字体,如此处所述

当我尝试使用此代码逐步完成时:

font_import(pattern = "Arial.ttf")
y

我收到此错误:

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

我检查了我确实有 Arial 字体: 在此处输入图像描述

我的问题是什么

标签: rggplot2fonts

解决方案


我遇到了同样的问题,即尝试使用font_import()并接收相同的错误导入字体(Zallman Caps):

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

经过大量的反复试验,我终于找到了一个对我有用的解决方案,也许它也对你有用。

尽管我可以在我的 Windows 字体文件夹中看到 Zallman Caps 字体并验证它在 Word 中有效,但在那里font_import()list.files()找不到它。我设法通过输入以下代码导入字体:

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

当我可以在 Windows 文件资源管理器中清楚地看到它时,我不知道为什么它在主字体目录中对 R 不可见,但至少我设法使用此解决方法导入了字体。


推荐阅读