Skip to content

Instantly share code, notes, and snippets.

@dpseidel
Created August 10, 2018 22:00
Show Gist options
  • 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 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