简体   繁体   English

extrafont::loadfonts(device = “win”) 在 Rprofile 中不起作用,但在控制台中很好

[英]extrafont::loadfonts(device = “win”) wouldn't work in Rprofile but fine in console

I was trying to follow Will Chase's advice on putting the loadfonts line in the.RProfile file so I can be executed before I customarily load ggplot2.我试图按照 Will Chase 的建议将 loadfonts 行放在 .RProfile 文件中,这样我就可以在通常加载 ggplot2 之前执行。 his advice 他的建议

Somehow I encountered this interesting phenomenon, when I write:不知怎的,我在写的时候遇到了这个有趣的现象:

if(interactive()) 
  try(extrafont::loadfonts(device = "win"))

RStudio gave an error RStudio 报错

Error in get(as.character(FUN), mode = "function", envir = envir) : 
  object 'windowsFonts' of mode 'function' was not found

Must be some behind the scene magic.一定是一些幕后魔术。 once I lay my hands on the console though, I can just run extrafont::loadfonts(device = "win") and it will be registering fonts with R using windowsFonts() .不过,一旦我把手放在控制台上,我就可以运行extrafont::loadfonts(device = "win") ,它将使用 windowsFonts windowsFonts()将 fonts 与 R 注册。

it seems windowsFonts function is not available when.RProfile is being interpreted.似乎windowsFonts function 在解释.RProfile 时不可用。 Not sure why, and any help to allow me to wrap my mind around this issue would be appreciated.不知道为什么,如果能帮助我解决这个问题,我们将不胜感激。

Way late on a response, but I was having the same issue and figured out a solution after reading this.回复晚了,但我遇到了同样的问题,并在阅读本文后找到了解决方案。 windowsFonts() is a function in grDevices library. windowsFonts() 是 grDevices 库中的 function。 extrafont imports grDevices, but for some reason it's not recognized when run in.Rprofile - it must have something to do with the order of operations when R loads. extrafont 导入 grDevices,但由于某种原因,它在运行时无法识别。Rprofile - 它必须与加载 R 时的操作顺序有关。 If you load grDevices it works.如果您加载 grDevices 它可以工作。 See code below.请参阅下面的代码。

library(extrafont)
loadfonts("win", quiet = F)

Error in get(as.character(FUN), mode = "function", envir = envir) : 
  object 'windowsFonts' of mode 'function' was not found
Calls: <Anonymous> -> match.fun -> get
Execution halted
library(grDevices)
library(extrafont)
loadfonts("win", quiet = F)
Registering fonts with R

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM