Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: polygon edge not found when using bayesplot #283

Open
njtierney opened this issue Feb 17, 2022 · 8 comments
Open

Error: polygon edge not found when using bayesplot #283

njtierney opened this issue Feb 17, 2022 · 8 comments
Labels

Comments

@njtierney
Copy link

Hi there!

Thanks for maintaining bayesplot!

I've got a bit of a funny issue that I was wondering if you have encountered with bayesplot. I find that sometimes, but not always, GitHub actions fails building a vignette when calling a function from bayesplot, giving the error:

Quitting from lines 469-474 (get_started.Rmd) 
  Error: processing vignette 'get_started.Rmd' failed with diagnostics:
  polygon edge not found
  --- failed re-building ‘get_started.Rmd’

(GH action line here: https://github.com/greta-dev/greta/runs/5233369273?check_suite_focus=true#step:11:245)

This is occurring at this line of the vignette:

https://github.com/greta-dev/greta/blob/master/vignettes/get_started.Rmd#L469-L473

Having a look around, it initially appeared that there was an issue with fonts: https://community.rstudio.com/t/ggplot2-polygon-edge-not-found/116475/4 - however, taking a look at your code it doesn't seem that there are custom fonts loaded, so I'm not sure why this is happening.

In any case, please do feel free to close this issue, I just thought in case you've come across this before, if you have any tips on how to resolve this!

Cheers!

@JasonPekos
Copy link

JasonPekos commented Oct 5, 2022

Just chiming in to say that I often encounter a similar bug when using bayesplot:

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found

This bug will randomly pop up, forcing an R restart before I can use any bayesplot functions or themes. I can run the same code multiple times, and only sometimes — probability < 0.05 as a rough guess — will this break my R session.


Here's some more info:

  • ggplot still works fine after this error shows up, but all bayesplot functions break
    • unless I use the bayesplot theme, in which case any plots will fail with the same error.
  • I am using an m1 macbook air running osx.
  • this issue can occur anywhere ... in quarto notebooks, in targets workflows, in plain R scripts ...
  • sometimes it seems like the error occurs when I'm not even running anything — I'll come back to my computer, and realize that my R session has broken. I'm a little unsure about this one because it could just be that I left a long computation (e.g. sampling) running in the background, but I really don't think so.

I've tried many of the fixes for similar issues online — e.g. validating fontbook, etc. — and none of them fix the issue. It's really difficult to track down what could be going wrong because it's not a deterministic bug, so any suggestions are very appreciated.

@JasonPekos
Copy link

JasonPekos commented Oct 7, 2022

Ok, found this ... seems like for me, it's probably a really crazy concurrency bug with quartz.

I'm not sure why ggplot still works for me without the bayesplot theme, but I think there's probably(?) nothing going wrong on bayesplot's end here.


Update: reinstalling X11 seems to have fixed the problem.

Second update: nope, it still shows up, but more less often now.

@jgabry jgabry added the bug label Nov 14, 2022
@jgabry
Copy link
Member

jgabry commented Nov 14, 2022

Sorry for the very slow reply! This got lost somewhere in my long list of issues to deal with.

Thank you both for reporting this. I also get this error occasionally and have been unable to figure out how to resolve it because I can't seem to deterministically reproduce it. Sometimes it happens during GitHub actions checks when building vignettes, like what @njtierney reported, other times it doesn't happen. I don't think I've ever had it happen in an interactive session.

This bug will randomly pop up, forcing an R restart before I can use any bayesplot functions or themes. I can run the same code multiple times, and only sometimes — probability < 0.05 as a rough guess — will this break my R session.

@JasonPekos Does it tend to be a particular bayesplot function where this initially happens?

@JasonPekos
Copy link

@jgabry I'm not sure if this will help you narrow it down, but I see the issue whenever I use the BayesPlot + theme_default(), even if I'm not calling a specific bayesplot function (e.g. mcmc_pairs() or whatever). So something like:

plot <-  ggplot() + theme_default()

And then adding some geoms with something like:

plot <- plot + geom_line(data = dat, 
                         aes(x = 1:nrow(dat), y = quant),
                         color = color_scheme_get()$light_highlight,
                         alpha = 0.1)

(I don't think the specifics are super important here, but this is an example of something that will break for me).

The error will show up here when I try to actually display the plot.


Note: Just so I don't send you down the wrong path, I am using mcmc_pairs() a lot in the same R session, so it could be that this is where the corruption ultimately stems from. Though I don't think so!

@JasonPekos
Copy link

JasonPekos commented Nov 19, 2022

Ok I actually have the problem currently in an interactive R session, here's a quick test: I can take the above code:

plot <-  ggplot() + theme_default()

plot <- plot  + geom_whatever()

And I get the error. I can go into my plotting functions and change the theme:

plot <-  ggplot() + theme_classic()

And remake the plots. When I do this, the error disappears1 and the plots display fine. So I think it's probably something do do with the BayesPlot theme.

1: Edit — disapears for only the new plots, bayesplot plots still won't display until I kill and restart my R session

@JasonPekos
Copy link

JasonPekos commented Nov 21, 2022

If this helps anyone narrow it down: I can test different output formats with:

ggsave(filename = "something.extension",
       plot = plotname)

The following don't work:

  • .png
  • .jpeg
  • .tiff
  • .bmp

That is, they fail with:

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found

The following don't work, but in a weird way:

  • .eps & .ps, which fail with:
Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  family 'serif' not included in postscript() device

(maybe my fault?)

The following probably work:

  • .tex (pictex)
    The pairs plot I tried throws the error:
./test.tex:4599: TeX capacity exceeded, sorry [main memory size=5000000].
\!plot ...menA \raise \!dimenB \copy \!plotsymbol 
                                                  \kern -\!dimenA \ignorespa...
l.4599 ...om 393.89 326.17 center at 393.89 323.13
                                                  
./test.tex:4599:  ==> Fatal error occurred, no output PDF file produced!

which I think just means the plot is too big for my TeX install? The actual output looks sane.

The following definitely work:

  • .pdf
  • .svg (with the svglite library)

Not much to say here. Output is fine.

@jgabry
Copy link
Member

jgabry commented Dec 2, 2022

Thanks @JasonPekos, that's really helpful! Much appreciated.

I'll try to make some time to dig into this further.

@ischmidt20
Copy link

Seeing the same issue (M1 macbook as well). Any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants