RStudio graphics device (RStudioGD): dev.size('in') !== par('din')

A snippet of the R help for function dev.size():

A two-element numeric vector giving width and height of the current device...
The size information in inches can be obtained by `par("din")

And for par('din'):

R.O. the device dimensions, (width, height) , in inches. See also dev.size...

This suggests that dev.size('in') == par('din'). As it should, because reporting two different dimension values for the same device only creates unnecessary complications.

Let's test this with the quartz and x11 graphics devices. Start a new R command line session and create a plot on a quartz device:

R > quartz(); plot(0:1, 0:1, xlim=c(0, 1), ylim=c(0, 1))

R > dev.size('in')
[1] 7 7

R > par('din')
[1] 7 7

R > dev.size('px')/dev.size('in')
[1] 72 72

R > dev.size('px')/par('din')
[1] 72 72

dev.size('in') == par('din') because both functions use the same 72 pixel/inch ratio.

On an x11 graphics device:

R > x11(); plot(0:1, 0:1, xlim=c(0, 1), ylim=c(0, 1))

R > dev.size('in')
[1] 6.9896 6.9896

R > par('din')
[1] 6.9896 6.9896

R > dev.size('px')/dev.size('in')
[1] 96 96

R > dev.size('px')/par('din')
[1] 96 96

dev.size('in') == par('din') because both functions use the same 96 pixel/inch ratio.

In RStudio on the RStudio graphics device:

R > plot(0:1, 0:1, xlim=c(0, 1), ylim=c(0, 1))

R > dev.size('in')
[1] 7 7

R > par('din')
[1] 5.25 5.25

R > dev.size('px')/dev.size('in')
[1] 72 72

R > dev.size('px')/par('din')
[1] 96 96

dev.size('in') !== par('din') because dev.size() uses a 72 pixel/inch ratio and par('din') uses a 96 pixel/inch ratio.

What is the rationale for this behavior?

R > sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
RStudio Version 1.1.453

Thanks for the investigation. RStudio constructs the graphics device by invoking the moral equivalent of:

grDevices::png(..., res = 96)  # or 192 for Retina displays

so I'm not exactly sure what we might be missing. Where is this causing issues for you?