When I click "Run current chunk" using the following chunk options creates an image of 164 × 164 pixels in the preview below the code in Rstudio's R markdown development environment:
{r, mychunk, fig.width=1.75, fig.height=1.61, dpi=600, retina=1}
However, when I knit the whole markdown file the resolution scales with increase of the DPI as expected, giving me a 1050 × 966 pixel image. Also the output of
message(knitr::opts_current$get('dpi'))
does not reflect the the DPI set in the chunk's header, when clicking on "Run current chunk". The dpi option is actually NULL. I want my knitted report to have high-resolution images for publishing. Therefore I use the chunk options fig.height, fig.width (in inches) and dpi according to specifications of the publisher. But unfortunately, in the inline preview, it translates to tiny figures. Probably because of a fixed dpi value that is used to create the plots below the code chunks.
I think it would be important for this inline execution mode to respect the DPI set in the header, because otherwise it is extremely difficult to debug figures. Knitting the whole report every time I change the code to create the plot is not an option, because it takes too long.
Reproducible example:
---
title: "R Notebook"
output: html_document
---
```{r, mychunk, fig.width=1.75, fig.height=1.61, dpi=600, fig.retina=1}
library(ggplot2)
message(paste0("dpi=", knitr::opts_current$get('dpi')))
ggplot(cars, aes(speed, dist)) + geom_point()
I am able to reproduce this for
- RStudio 1.1.383 on Ubuntu 16.04/GNOME Shell 3.18.5
- RStudio 1.1.463 on Ubuntu 18.04/GNOME Shell 3.28.3