为什么RStudio显示手动编织的pdf错误? [英] Why does RStudio show the manually knitted pdf wrong?

查看:73
本文介绍了为什么RStudio显示手动编织的pdf错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Mac OS X Mountain Lion 10.8.4上运行最新的RStudio(0.97.551)和R(3.0.1)版本.

I'm running the latest RStudio (0.97.551) and R (3.0.1) version on Mac OS X Mountain Lion 10.8.4.

我有以下两个文件: test.Rnw

I have the following two files: test.Rnw

\documentclass{article}

<<set-options, echo=FALSE>>=
 options(replace.assign=TRUE)
 opts_chunk$set(external=TRUE, cache=TRUE, echo=FALSE, fig=TRUE)
 read_chunk('chunks.R')
@

\begin{document}
\section{Graphics}

<<chart, fig.height=4>>=
@

\end{document}

和大块.R

## @knitr chart
library(ggplot2, quietly=TRUE)
Sys.sleep(3)
p <- ggplot(mtcars, aes(wt, mpg))  + geom_point(aes(size = qsec)) +
   labs(title ="title with umlauts ä")
p
sessionInfo() 

在RStudio中编织此文档时,一切都很好:

When knitting this document in RStudio everything is fine:

现在,我清除缓存并从运行命令的脚本中手动编织文档:

Now I clear the cache and knit the document manually from a script running the commands:

export TEXINPUTS=$TEXINPUTS:/Library/Frameworks/R.framework/Versions/Current/Resources/share/texmf/tex/latex/
/usr/bin/Rscript -e "library(knitr); knit(\"test.Rnw\")"
pdflatex ./test.tex

一切都还好.

但是然后我不清除缓存并在RStudio中再次进行编织. RStudio的PDF查看器现在将显示以下图表:

But then I don't clear the cache and knit again in RStudio. the PDF-viewer of RStudio now displays the chart as follows:

Mac OS X Preview可以很好地显示两个pdf.我可以看到的sessionInfo()的唯一区别是基本包的顺序.

Mac OS X Preview shows both pdfs fine. The only difference in sessionInfo() I can see is the order of the base packages.

有人知道RStudio为什么显示图形错误吗?

Has anyone an idea why RStudio shows the graphic wrong?

我不知道如何共享两个pdf.因此,如果有人需要它们并告诉我如何共享它们,我会做的.

I don't know how to share the two pdfs. So if anyone needs them and tells me how to share them, I'll do it.

TIA, JW

推荐答案

RStudio在调用knitr之前先设置grDevices::pdf.options(useDingbats = FALSE)(请参见包含日志的面板Compile PDF),并且选项useDingbats在R中是默认设置.RStudio的内置PDF查看器不支持Dingbats字体,因此当useDingbats = TRUE时,圆圈(实心点)在其PDF查看器中被打断了.有关更多信息,请参见?pdf.

RStudio sets grDevices::pdf.options(useDingbats = FALSE) before it calls knitr (see the panel Compile PDF which contains the log), and the option useDingbats is TRUE by default in R. RStudio's built-in PDF viewer does not honor the Dingbats font, so the circles (solid points) were broken in its PDF viewer when useDingbats = TRUE. See ?pdf for more information.

您不应使用RStudio的PDF查看器自行查看RStudio的外部生成的PDF. Tools -> Options -> Sweave -> PDF preview中还有其他不错的选择,例如Windows下的Sumutra PDF和Linux下的evince.不过,我对Mac OS X一无所知(我相信至少您可以使用系统的默认查看器).

You should not use RStudio's PDF viewer to view the PDF generated outside of RStudio by yourself. There are other good choices in Tools -> Options -> Sweave -> PDF preview, such as Sumutra PDF under Windows, and evince under Linux. I have no idea about Mac OS X, though (at least you can use the default viewer of the system, I believe).

这篇关于为什么RStudio显示手动编织的pdf错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆