knitr: fig.height must be numeric in new version?

738 views Asked by At

I downloaded a new version of the knitr package and suddenly I get the following error when trying to include a plot in an Rnw file:

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%

After a lot of experimenting I found out the problem is with the command fig.height, apparently it is supposed to be numeric. This code produces the error:

\documentclass{article}

\begin{document}

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

\end{document}

This code does not:

\documentclass{article}

\begin{document}

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

\end{document}

Unfortunately I have no idea what the unit of measurement for this 6 is.

This code:

\documentclass{article}

\begin{document}

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

\end{document}    

produces a different error:

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 

All in all it seems as if knitr is really expecting a numeric value for fig.height, which is moderately annoying because I have already typed a lot of fig.height='\\textheight' commands throughout my document (back in the days that that still worked) and I also do not really know what the numeric value corresponding to Latex's \textheight is.

Any advise?

UPDATE: I did some more experimenting and it turns out that the numbers you feed to fig.height appear nowhere in the Latex-file, instead they influence the dimension of the cat.pdf image produced by knitr directly. This kind of suggest that leaving out fig.height altogether might be the best strategy. Still this doesn't tell us how to get the [height=\textheight] in the tex document.

1

There are 1 answers

0
Yihui Xie On BEST ANSWER

Use the chunk option out.height instead of fig.height.