Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Sweave Computer Modern font usage

Tags:

r

fonts

sweave

I've installed the R packages extrafont and fontcm. Then tried to plot the data with Computer Modern font in Sweave:

<<test,fig=TRUE,echo=False>>=
plot(na, family="CM Roman")
@

But it fails with error:

> grDevices::pdf.options(useDingbats = FALSE); utils::Sweave('test.Rnw', encoding='UTF-8')
Writing to file test.tex
Processing code chunks with options ...
 1 : echo keep.source term verbatim (test.Rnw:76)
 2 : keep.source term verbatim pdf  (label = test, test.Rnw:80)

Error:  chunk 2 (label = test) 
Error in axis(side = side, at = at, labels = labels, ...) : 
  invalid font type
In addition: Warning messages:
1: In axis(side = side, at = at, labels = labels, ...) :
  font family 'CM Roman' not found in PostScript font database
2: In axis(side = side, at = at, labels = labels, ...) :
  font family 'CM Roman' not found in PostScript font database
3: In axis(side = side, at = at, labels = labels, ...) :
  font family 'CM Roman' not found in PostScript font database
4: In axis(side = side, at = at, labels = labels, ...) :
  font family 'CM Roman' not found in PostScript font database
5: In axis(side = side, at = at, labels = labels, ...) :
  font family 'CM Roman' not found in PostScript font database
6: In axis(side = side, at = at, labels = labels, ...) :
  font family 'CM Roman' not found in PostScript font database
7: In axis(side = side, at = at, labels = labels, ...) :
  font family 'CM Roman' not found in PostScript font database
Error in rle(filenames) : 'x' must be an atomic vector
Calls: <Anonymous> -> <Anonymous> -> RweaveTryStop
Execution halted

loadfonts(device="postscript") shows that fonts is already registered with postscriptFonts()

How can I use it with Sweave?

like image 579
m0nhawk Avatar asked Apr 18 '13 18:04

m0nhawk


2 Answers

Are you sure you are using the right name? Try this and see if the results are informative:

> names(postscriptFonts() )
 [1] "serif"                "sans"                 "mono"                 "AvantGarde"          
 [5] "Bookman"              "Courier"              "Helvetica"            "Helvetica-Narrow"    
 [9] "NewCenturySchoolbook" "Palatino"             "Times"                "URWGothic"           
[13] "URWBookman"           "NimbusMon"            "NimbusSan"            "URWHelvetica"        
[17] "NimbusSanCond"        "CenturySch"           "URWPalladio"          "NimbusRom"           
[21] "URWTimes"             "ComputerModern"       "ComputerModernItalic" "Japan1"              
[25] "Japan1HeiMin"         "Japan1GothicBBB"      "Japan1Ryumin"         "Korea1"              
[29] "Korea1deb"            "CNS1"                 "GB1"                 

On review I see that pdf.options was involved and you may also need to examine:

 > names( pdfFonts() )
like image 96
IRTFM Avatar answered Nov 14 '22 12:11

IRTFM


Appears to be a stupid and easy question. I need to load extrafont and fontcm packages in my Sweave file:

<<setup,echo=FALSE>>=
    library(extrafont)
    library(fontcm)
@
like image 3
m0nhawk Avatar answered Nov 14 '22 12:11

m0nhawk