Skip to content

Instantly share code, notes, and snippets.

@noamross
Created December 10, 2016 21:59
Show Gist options
  • Save noamross/281147ea018ef840ca1cc25495df563f to your computer and use it in GitHub Desktop.
Save noamross/281147ea018ef840ca1cc25495df563f to your computer and use it in GitHub Desktop.
Bug in R quartz() device
# I believe I found a bug in R's quartz() device, specifically it's
# GECap method (the C routine called by dev.capture). The following
# yields the two images in the comment below. This occurs whether working
# from the terminal or RStudio. This works fine with Cairo devices that
# support raster capture.
quartz()
plot(1,1)
aa <- dev.capture()
dev.size("px")
#> [1] 504 504
dim(aa)
#> [1] 751 795
# Note that the size of the raster does not match the device size.
plot(as.raster(aa)) # Looks way different.
tail(table(aa))
#> #FFF9F9 #FFFBFB #FFFEFE red snow white
#> 1 4 2 3420 1 589997
# Note all the red pixels in what should be a black and white image
dim(aa)
# I note I am on a retina Macbook. I have XQuartz 2.7.8.
devtools::session_info()
# Session info ------------------------------------------------------------------
# setting value
# version R version 3.3.2 (2016-10-31)
# system x86_64, darwin13.4.0
# ui X11
# language (EN)
# collate en_US.UTF-8
# tz America/New_York
# date 2016-12-10
#
# Packages ----------------------------------------------------------------------
# package * version date source
# crayon * 1.3.2 2016-06-28 cran (@1.3.2)
# devtools 1.12.0.9000 2016-12-08 Github (hadley/devtools@1ce84b0)
# digest 0.6.10 2016-08-02 cran (@0.6.10)
# memoise 1.0.0.9001 2016-12-04 Github (hadley/memoise@e392c7b)
# pkgbuild 0.0.0.9000 2016-11-28 Github (r-pkgs/pkgbuild@65eace0)
# pkgload 0.0.0.9000 2016-11-28 Github (r-pkgs/pkgload@def2b10)
# rstudioapi 0.6 2016-06-27 cran (@0.6)
# withr 1.0.2 2016-06-20 CRAN (R 3.3.0)
@noamross
Copy link
Author

First Plot:

plot1

Second Plot:

plot2

@bbolker
Copy link

bbolker commented Dec 11, 2016

I get the red graph too, not as ugly as Noam's (unless Noam's has been mangled in uploading); margins are about as different as one would expect from the reported difference between device size and capture size.

@noamross
Copy link
Author

noamross commented Dec 11, 2016

No, it wasn't mangled in upload, that's how it looks on my machine. I have a suspicion it has to do with the retina screen.

@s-u
Copy link

s-u commented Dec 13, 2016

Thanks, the RGBA vs ARGB issue should now be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment