Reprex failed to generate output when ggplot is included

Hi all, I was in a call with a colleague with some one who was trying to create a reprex example, with a code that has a ggplot example at the end of the code. They keep getting the following error.

image
The same reprex example works fine on my end, without a problem. Also when they run the code without the reprex everything works fine. I have tried to update R and Rstuido, and all R packages. Checked the windows updates, all up-to-date. I have also tried to install some font packages `install.packages(c("svglite","systemfonts","textshaping"))`, but this time didn’t help.
checked for the updates in shiny and rstuidoAPI as well but there was no lack.
Any help would be appreciated.
@luisquezada @swateja11

Hey Berhe,

A few things for your colleague to check:

  1. Try a minimal ggplot reprex

    reprex::reprex({
      library(ggplot2)
      ggplot(mtcars, aes(mpg, wt)) + geom_point()
    }, std_out_err = TRUE)
    
    

    If this already fails, the problem is not the specific code but their setup.

  2. Check and reset the graphics device option
    Try running:

    getOption("device")
    
    

    If it’s "RStudioGD" (or another custom device), that’s not available in the headless session reprex() uses and can cause a crash. Set it back to a standard device:

    options(device = NULL)          # or on Windows: options(device = "windows")
    
    
  3. Check .Rprofile / startup code
    Look for anything that sets options(device = "RStudioGD") or similar,

  4. Verify svg device works
    Since reprex uses {svglite} by default:

    svglite::svglite(file = tempfile(fileext = ".svg"))
    plot(1:5)
    dev.off()
    
    

    If this errors, reinstall:

    install.packages(c("svglite", "systemfonts", "textshaping"))
    
    

In most cases this “appears to crash R” error with ggplot+reprex ends up being caused by a non-default graphics device or font/theme setting in the user’s startup files, not by reprex() itself.

Let me know!

Best,

Luis