Skip to content

Instantly share code, notes, and snippets.

@dpseidel
Created August 10, 2018 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpseidel/322db7110b8590d77ba20f3db8f399fc to your computer and use it in GitHub Desktop.
Save dpseidel/322db7110b8590d77ba20f3db8f399fc to your computer and use it in GitHub Desktop.
debugging the "polygon edge not found" error
#### This is a script useful for debugging the very tricky, intermittent,
#### "polygon edge not found" error triggered in grid when using the RstudioGD and quartz devices
library(ggplot2)
#system info
getOption("bitmapType") # this needs to be quartz
getOption("device") # this needs to be RStudioGD
# blank plot
blank_base <- ggplot(data.frame(), aes(1, 1)) +
theme(
axis.title.y = element_blank(),
axis.title.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank()
)
# with "graticule" labels matching output of sf::st_graticule
p <- blank_base + scale_x_continuous(labels = c(
expr(160 * degree * W), expr(140 * degree * W),
expr(120 * degree * W), expr(100 * degree * W),
expr(0 * degree * W)
))
# with superscripts -- ala scales::math_format. higher failure rate typically
q <- blank_base + scale_x_continuous(labels = c(
expr(10 ^ 1), expr(10 ^ 2),
expr(10 ^ 3), expr(10 ^ 4),
expr(10 ^ 5)
))
# Simulate it... function
plot_ok <- function(p) {
tryCatch({
print(p)
TRUE
}, error = function(e) {
#print(e)
return(FALSE)
}
)
}
(sim <- replicate(50, plot_ok(q)))
sum(sim) / 50
@pmur002
Copy link

pmur002 commented Aug 14, 2018

Thanks for this. I wanted to run it myself to make sure that it does not fail on my setup, but there is at least one dependency missing (e.g., 'rlang' for expr() ?). Also, is this designed for ggplot2 development version or the CRAN version? Thanks for any clarificaitons

@dpseidel
Copy link
Author

dpseidel commented Aug 29, 2018

@pmur002 I'm so sorry for the delay, I only saw your message now. This works with either version of ggplot, 3.0.0 (on CRAN) or 3.0.0.9000; I have run it on both. Also, as of version 3.0.0 ggplot2 imports and reexports expr from rlang so you shouldn't need any additional dependencies. Please let me know if you need any other clarification.

@pmur002
Copy link

pmur002 commented Sep 7, 2018

Thanks. I can now run this. Of course, on my setup this does not fail (yet), but at least I can run it to check! :)

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