Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8613881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:59:14+00:00 2026-06-12T04:59:14+00:00

I know that in R on Linux or Mac, fonts are consistently defined as

  • 0

I know that in R on Linux or Mac, fonts are consistently defined as an argument family=”Charis SIL” to par(), text(), or one of the graphic device functions like tiff(), svg(), etc (substitute “Charis SIL” with whatever font name you want). I also know that on Windows, that only works for the cairo_pdf() and svg() devices; raster graphic devices like jpeg(), tiff(), png(), and bmp() require that the font be mapped in the “Windows font database” first:

# this doesn't work on windows
jpeg(filename='test1.jpg', family='Charis SIL')
plot(0,0,type='n',ann=FALSE,frame.plot=FALSE)
text(0,0,labels='iyeøɛœaɶɪʏæɑɒʌɔɤoɯuʊɨʉɘɵəɜɞɐɚɝ')
dev.off()
# (gives warnings: Font family not found in Windows font database)  

# this does work on windows (assuming you have the Charis SIL font installed)
windowsFonts(myCustomWindowsFontName=windowsFont('Charis SIL'))
jpeg(filename='test2.jpg', family='myCustomWindowsFontName')
plot(0,0,type='n',ann=FALSE,frame.plot=FALSE)
text(0,0,labels='iyeøɛœaɶɪʏæɑɒʌɔɤoɯuʊɨʉɘɵəɜɞɐɚɝ')
dev.off()

The pdf() device is different still: it seems to need fonts defined in either the postscriptFonts() and/or pdfFonts() database, which means only Type1 fonts:

# this doesn't work on windows
pdf('test.pdf', family='Charis SIL')
# gives error: Unknown family "Charis SIL"

# this doesn't work either
windowsFonts(myCustomWindowsFontName=windowsFont('Charis SIL'))
pdf('test.pdf', family='myCustomWindowsFontName')
# gives error: Unknown family "myCustomWindowsFontName"

# this also won't work
pdf.options(family='Charis SIL')
pdf('test.pdf')
# gives error: Invalid font type
# also gives warning: font family "Charis SIL" not found in Postscript font database

Ordinarily this would not matter, because cairo_pdf() is a fine substitute for the pdf() device and handles TTF and OTF fonts just fine. The problem is that if a user plots to the onscreen device and then uses the menu commands to save as PDF, it appears to call pdf() instead of cairo_pdf(), which then throws errors:

# this part works
windowsFonts(myCustomWindowsFontName=windowsFont('Charis SIL'))
par(family='myCustomWindowsFontName')
plot(0,0,type='n',ann=FALSE,frame.plot=FALSE)
text(0,0,labels='iyeøɛœaɶɪʏæɑɒʌɔɤoɯuʊɨʉɘɵəɜɞɐɚɝ')

# but menu command "File > Save As > PDF" gives errors:
# Error: Invalid font type
# Warning: font family "Charis SIL" not found in Postscript font database

This is a problem because the R package I’m developing keeps failing “R CMD check” on Windows, apparently because the example code generates on-screen output that gets saved out as PDF automatically, which generates the above-mentioned errors. One solution is to give up custom fonts for the on-screen devices in Windows (i.e., just ignore the “family” argument if the chosen output is “screen”). Another option is to use the Cairo() package for onscreen plotting, but I’d prefer to stick with base graphics if I can. Is there any way I can get custom fonts in an onscreen plot and not have it throw errors when using the “save as PDF” menu commands?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:59:15+00:00Added an answer on June 12, 2026 at 4:59 am

    The way I eventually solved this was as follows:

    oldSans <- windowsFonts()$sans
    windowsFonts(sans=windowsFont('Charis SIL'))
    par(family='sans') # this line isn't necessary anymore
    plot(0,0,type='n',ann=FALSE,frame.plot=FALSE)
    text(0,0,labels='iyeøɛœaɶɪʏæɑɒʌɔɤoɯuʊɨʉɘɵəɜɞɐɚɝ')
    windowsFonts(sans=oldSans)
    

    In this way, the correct font will be used in the on-screen window, and when the user uses the menu commands to save as PDF, the PDF will get saved out but with the default sans font instead of the custom one. It is a “solution” only in the sense that the PDF does get exported, but if the plot has non-ASCII glyphs there is no guarantee that they’ll show up in a PDF generated in this way. It is also arguably WORSE than the original situation, because the action no longer throws an error or even a warning. The moral of the story: don’t rely on the menu commands in your GUI to do things that you should know how to do in the console.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using mac/linux and I know that ctrl-z stops the currently running command in
I know that I can check whether the linux timestamp in $time is today
I know there are various linux packages that allow you to crop a portion
Anyone know what function or file in linux holds the algorithm that finds a
I know that this line of code will make the cell text-wrap: $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true); 'D1'
I have a few applications that might qualify for porting over to a Linux/Mac
Official Mono project website says that Mono works successfully on Windows, Linux and Mac
I am trying to port a project (from linux) that uses Semaphores to Mac
I would just like to know... Does this code work in linux and mac
I'm looking for a desktop publishing platform for Mac, Windows, and Linux that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.