Use a custom font within

I have the following code (placed at the top of my app.R file, just after my library() calls):



.libPaths(c('r-lib', .libPaths()))

install.packages('r-lib/extrafontdb_1.0.tar.gz',type = 'source',repos = NULL)


download.file("** GIT USER NAME **/fonts/archive/master/", destfile = "")

unzip("", exdir = "~/.fonts")


system('fc-cache -f ~/.fonts')


The above aims to:

  • Download and install extrafontdb (as i want to be able to save and access fonts to this db)
  • Create a .fonts directory
  • Download my custom fonts from Github
  • Import the .ttf files to the db
  • Tell the system where the fonts are stored

The last line is a function as follows:

gg_set_the_theme <- function(base_size=10, base_family="Sarabun") {

 extrafont::loadfonts("win", quiet = TRUE)

 ggplot2::theme_set(gg_the_theme(base_size=10, base_family=base_family))

Note: "gg_the_theme" is just a function to style colours and sizes within "ggplot2::theme".

I then publish to and it fails to deploy with this error message:

trying URL ''
Content type 'application/x-gzip' length 1672 bytes
downloaded 1672 bytes

Installing package into ‘/srv/connect/apps/** APP NAME **/r-lib’
(as ‘lib’ is unspecified)
* installing *source* package ‘extrafontdb’ ...
** package ‘extrafontdb’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (extrafontdb)
trying URL '** GIT USER NAME **/fonts/archive/master/'
downloaded 2.9 MB

Scanning ttf files in ~/.fonts ...
Extracting .afm files from .ttf files...
Found FontName for 19 fonts.
Scanning afm files in /srv/connect/apps/** APP NAME **/r-lib/extrafontdb/metrics
Writing font table in /srv/connect/apps/** APP NAME **/r-lib/extrafontdb/fontmap/fonttable.csv
Writing Fontmap to /srv/connect/apps/** APP NAME **/r-lib/extrafontdb/fontmap/Fontmap...
Error in value[[3L]](cond) : could not find function "windowsFonts"
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

However, it looks as though the fonts i wanted to import are there (as my github file contains 19 .ttf files). I'm not sure why or where this "windowsFonts" function would be required. Perhaps there is an issue with the fact my code is designed for windows and not linux (as this is what uses)?

Any help would be greatly appreciated.

Thanks, Matt

Duplicated over here a week ago,

Folks should be aware of our cross post policy, FAQ: Is it OK if I cross-post?

Thanks EconomiCurtis, i posted here only after i had no response on SO. I hope this is okay. Matt