Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 我无法使用字体导入导入字体_R_Ggplot2_Fonts - Fatal编程技术网

R 我无法使用字体导入导入字体

R 我无法使用字体导入导入字体,r,ggplot2,fonts,R,Ggplot2,Fonts,我正在尝试导入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

我正在尝试导入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字体:

我的问题是什么

请检查文件名 tl;drWindows不区分大小写,但R的
grepl
不区分大小写,并且
import\u font
传递模式参数
grepl

使用:

为什么??因为Windows返回“arial.ttf”作为文件名

文件资源管理器不显示字体文件名 模式“Arial.ttf”将匹配
C:\Windows\Fonts\Arial.ttf
。但是在我的测试系统上,该文件只是
C:\Windows\Fonts\Arial
,没有扩展名。这是使用文件资源管理器查看目录时看到的内容。文件资源管理器没有显示如下所示的文件名

使用R或powershell查找字体文件 通过这些方法中的任何一种,文件名的输出都是
arial.ttf

使用powershell 全部显示文件名
arial.ttf

使用R
font\u import
如何使用模式参数 查看
font\u import
如何使用提供的模式:

extrafont::font_import # prints the source
#function (paths = NULL, recursive = TRUE, prompt = TRUE, pattern = NULL) 
#{
#...
#    ttf_import(paths, recursive, pattern)
#}

extrafont:::ttf_import # print the source
#function (paths = NULL, recursive = TRUE, pattern = NULL) 
#{
#    if (is.null(paths)) 
#        paths <- ttf_find_default_path()
#    ttfiles <- normalizePath(list.files(paths, pattern = "\\.ttf$", 
#        full.names = TRUE, recursive = recursive, ignore.case = TRUE))
#    if (!is.null(pattern)) {
#        matchfiles <- grepl(pattern, basename(ttfiles))
#        ttfiles <- ttfiles[matchfiles]
#    }
#...
#}


我遇到了相同的问题,即尝试使用
font\u import()
导入字体(Zallman Caps),但收到了相同的错误:

"Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : 
   arguments imply differing number of rows: 0, 1"
经过大量的尝试和错误,我终于找到了一个对我有效的解决方案,也许对你也是如此

尽管我可以在Windows Fonts文件夹中看到Zallman Caps字体并验证它在Word中是否有效,但无论是
font\u import()
还是
list.files()
都无法在那里找到它。我通过输入以下代码成功导入字体:

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

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

似乎
模式
区分大小写。请尝试
font\u导入(pattern=“arial.ttf”)
。谢谢您的输入。但是,我在尝试
extrafont::font\u导入(pattern=“Arial$”,prompt=FALSE)
时遇到了我提到的错误,也就是说我仍然有:
在C:\windows\font中扫描ttf文件。。。正在从.ttf文件中提取.afm文件。。。data.frame(fontfile=ttfiles,FontName=”,stringsAsFactors=FALSE)中出错:参数表示行数不同:0,1
能否验证Arial字体文件是否存在?它确实存在(我在初始问题中添加了一张图片)。@powershell中的AnthonyMartin在字体目录中查看了Arial
ls C:\Windows\Fonts | findstr-i'arial'
,它显示为
arial.ttf
。看来资本化是个问题。试试`pattern=“arial.ttf”。似乎Windows文件资源管理器正在帮助显示名称不同于其文件名的ttf字体文件。我想我最初的问题涵盖了这两个主题,但我将对其进行编辑,以便其中一个是关于第二部分,以便有人可能会发现显示的字体不一定是要抓取的字体,并按照您的建议创建一个新的。谢谢!这正是我需要的。啊,谢谢!这就是我这些年来一直在寻找的答案!
extrafont::font_import # prints the source
#function (paths = NULL, recursive = TRUE, prompt = TRUE, pattern = NULL) 
#{
#...
#    ttf_import(paths, recursive, pattern)
#}

extrafont:::ttf_import # print the source
#function (paths = NULL, recursive = TRUE, pattern = NULL) 
#{
#    if (is.null(paths)) 
#        paths <- ttf_find_default_path()
#    ttfiles <- normalizePath(list.files(paths, pattern = "\\.ttf$", 
#        full.names = TRUE, recursive = recursive, ignore.case = TRUE))
#    if (!is.null(pattern)) {
#        matchfiles <- grepl(pattern, basename(ttfiles))
#        ttfiles <- ttfiles[matchfiles]
#    }
#...
#}

matchfiles <- grepl(pattern, basename(ttfiles))
"Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : 
   arguments imply differing number of rows: 0, 1"
font_import(path = "C:/Users/*insert your user name*/AppData/Local/Microsoft/Windows/Fonts", pattern = ".TTF")