3

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. his advice

Somehow I encountered this interesting phenomenon, when I write:

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

RStudio gave an error

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().

it seems windowsFonts function is not available when .RProfile is being interpreted. Not sure why, and any help to allow me to wrap my mind around this issue would be appreciated.

PaulDong
  • 711
  • 7
  • 19

1 Answers1

1

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. 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. If you load grDevices it works. 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
Mark Druffel
  • 629
  • 4
  • 10