I recently got a new macbook pro and am having some R graphics related problems on it. R is working insanely slowly when plotting sf objects. I found a thread that's a couple of years old on this issue (here: https://github.com/rstudio/rstudio/issues/3866), but no solution was ever proposed. For reference, RStudioGD
is plotting the object >300x more slowly than pdf
and it's making me crazy. Sharing the reproducible example from the link above here (though the system time numbers are mine):
<<================= copy from link above: ===========================>>
I wanted to plot the shapefile for Myanmar found here:
https://gadm.org/download_country_v3.html
library(rgdal)
library(sp)
tdir = tempdir()
get_poly = function() {
tmp = tempfile(tmpdir = tdir)
download.file(
'https://biogeo.ucdavis.edu/data/gadm3.6/shp/gadm36_MMR_shp.zip',
tmp
)
unzip(tmp, exdir = tdir)
readOGR(tdir, 'gadm36_MMR_0', stringsAsFactors = FALSE)
}
Plotting this with RStudioGD is much, much slower than to e.g. pdf:
mmr = get_poly()
system.time(plot(mmr))
# user system elapsed
# 128.162 0.510 129.271
unlink(tdir, recursive = TRUE)
Restart R to clear cache/overhead and run again:
mmr = get_poly()
tpdf = tempfile(tmpdir = tdir, fileext = 'pdf')
system.time({
pdf(tpdf)
plot(mmr)
dev.off()
})
# user system elapsed
# 0.423 0.027 0.460
unlink(tdir, recursive = TRUE)
So using the external device is about 300x faster... any idea?
png also takes < 1 second
<<=================== end copy from link =======================>>
I am on macOS Big Sur 11.1
RStudio version 1.3.1093
(I am having some other vague graphics-related problems that I posted about here: quartz device behaving strangely after mac update - R mac, but I am not sure if the two are related or not).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…