我已经安装了R包extrafont和fontcm.然后尝试使用Sweave中的Computer Modern字体绘制数据:
<<test,fig=TRUE,echo=False>>=
plot(na, family="CM Roman")
@
Run Code Online (Sandbox Code Playgroud)
但它失败了,错误:
> 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
Run Code Online (Sandbox Code Playgroud)
loadfonts(device="postscript") 表明字体是 already registered with postscriptFonts()
我怎样才能将它与Sweave一起使用?
似乎是一个愚蠢而简单的问题。我需要在我的 Sweave 文件中加载extrafont并打包:fontcm
<<setup,echo=FALSE>>=
library(extrafont)
library(fontcm)
@
Run Code Online (Sandbox Code Playgroud)