knitr and rgl: inconsistent size?

238 views Asked by At

I am trying to write a vignette for the rgl package. I figured I would try to use knitr and markdown to produce an HTML vignette, so that I could include interactive displays as well as snapshots.

Recent versions of Rstudio include pandoc and use the rmarkdown package to process the input into HTML, but not all systems (including apparently R-forge) include pandoc, and knitr falls back to some older version of markdown processing on those.

What I am finding is that I get different sizes reported to my rgl device depending on whether I am using the pandoc path or the older one. Using Yihui's knitr::hook_webgl function as the hook, the images end up twice the size they should. The size in pixels is computed in that function using the line

rgl::par3d(windowRect = 100 + options$dpi * c(0, 0, options$fig.width, options$fig.height))

Here, options is one of the arguments passed to the function. It contains the chunk options.

To get the size right, I need to divide the dpi by 2. On the other hand, using the same code with the older driver works fine.

Is this a bug in knitr, or am I missing some option somewhere?

Here's a sample produced using pandoc in RStudio, with hook_rgl modified to divide the size by 2. The figures are the size I want:

http://www.stats.uwo.ca/faculty/murdoch/temp/rgl.html

And here's the same input file processed on a system without pandoc. Notice that the rgl figures are half as big:

http://www.stats.uwo.ca/faculty/murdoch/temp/rgl2.html

1

There are 1 answers

0
user2554330 On BEST ANSWER

I've found the explanation for the difference. When pandoc is present, knitr reports to the chunk hook that options$dpi is 192. When it is not present, the chunk hook is told options$dpi is 72.

The workaround I'll adopt is to ignore options$dpi, and fix dpi at 96 in my rgl hook function.