1
votes

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
how do you have options defined? unless you have over written options(), then you should get an error with options$dpi - rawr
options is an argument to hook_rgl. The header is function (before, options, envir). - user2554330
how is that relevant? that's not the issue nor what I asked, that's not the function you are using (rgl::par3d), and that's not how you are using options - rawr
I was quoting a line from knitr::hook_rgl. options is an argument to that function. (In fact, it's knitr::hook_webgl that is relevant, but they both have that line. I'll edit my question to change hook_rgl to hook_webgl.) - user2554330
Just for the record, the issue has been reported to github.com/yihui/knitr/issues/901 - Yihui Xie

1 Answers

2
votes

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.