knitr:新版本中fig.height必须是数字吗?

Vin*_*ent 0 latex knitr rnw

我下载了新版本的 knitr 包,当尝试在 Rnw 文件中包含绘图时突然出现以下错误:

Error in options[[sprintf("fig.%s", i)]] * options$dpi : 
  non-numeric argument to binary operator
Calls: knit ... process_group.block -> call_block -> fix_options -> %n%
Run Code Online (Sandbox Code Playgroud)

经过大量实验后,我发现问题出在命令 Fig.height 上,显然它应该是数字。此代码产生错误:

\documentclass{article}

\begin{document}

<<cat, fig.cap="dog", fig.height='\\textheight'>>=
plot(c(1, 2, 3), c(2, 1, 3))
@

\end{document}
Run Code Online (Sandbox Code Playgroud)

这段代码没有:

\documentclass{article}

\begin{document}

<<cat, fig.cap="dog", fig.height=6>>=
plot(c(1, 2, 3), c(2, 1, 3))
@

\end{document}
Run Code Online (Sandbox Code Playgroud)

不幸的是我不知道这个 6 的测量单位是什么。

这段代码:

\documentclass{article}

\begin{document}

<<cat, fig.cap="dog", fig.height=6cm>>=
plot(c(1, 2, 3), c(2, 1, 3))
@

\end{document}    
Run Code Online (Sandbox Code Playgroud)

产生不同的错误:

Error in base::parse(text = code, srcfile = NULL) : 
  1:44: unexpected symbol
1: alist( 'cat', fig.cap="dog", fig.height=6cm
                                           ^
Calls: knit ... withCallingHandlers -> eval -> parse_only -> <Anonymous>
Execution halted 
Run Code Online (Sandbox Code Playgroud)

总而言之,似乎 knitr 确实期望 Fig.height 的数值,这有点烦人,因为我已经fig.height='\\textheight'在整个文档中输入了很多命令(在仍然有效的日子里),而且我也没有真正知道Latex对应的数值\textheight是什么。

有什么建议吗?

更新:我做了一些更多的实验,结果发现您提供给Fig.height的数字在Latex文件中没有出现,而是直接影响knitr生成的cat.pdf图像的尺寸。这种建议完全排除fig.height可能是最好的策略。但这并没有告诉我们如何获取[height=\textheight]tex 文档中的 。

Yih*_*Xie 5

使用 chunk 选项out.height而不是fig.height.