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

reprex with a plot fails (because imgur upload fails due to the API key quota being exhausted) #475

Open
DavoOZ opened this issue Jan 13, 2025 · 2 comments

Comments

@DavoOZ
Copy link

DavoOZ commented Jan 13, 2025

The following code, when selected in RStudio and submitted to {reprex} via the Addins menu ("Reprex selection"), causes the R session to crash. Not sure why. Code runs fine from the Source pane.

suppressPackageStartupMessages(library(tidyverse))
library(relaimpo)

# Regresses first column (mpg) against the other 10 variables
model <- calc.relimp(mtcars,
                     type = c("lmg","last","first","pratt"),
                     rela = TRUE)
plot(model)
str(model)
summary(model)

mod.df <- data.frame(lmg = model$lmg * 100,
                     first = model$first * 100,
                     last = model$last * 100,
                     pratt = model$pratt * 100)
mod.df

mod.df %>%
  rownames_to_column(var = "Variable") %>%
  pivot_longer(cols=2:5,
               names_to = "Method",
               values_to = "% of R2") %>%
  arrange(Method, Variable) -> long.df

head(long.df)

ggplot(data=long.df) +
  aes(x=Variable, y=`% of R2`) +
  geom_col() +
  facet_wrap(~ Method, nrow=2, ncol=2) +
  labs(title=(paste("Relative importances for", names(mtcars)[1])))

My machine specs and software setup are as follows:

library(sessioninfo)
session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.2 (2024-10-31 ucrt)
#>  os       Windows 11 x64 (build 26100)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_Australia.utf8
#>  ctype    English_Australia.utf8
#>  tz       Australia/Sydney
#>  date     2025-01-13
#>  pandoc   3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.3   2024-06-21 [1] CRAN (R 4.4.2)
#>  digest        0.6.37  2024-08-19 [1] CRAN (R 4.4.2)
#>  evaluate      1.0.3   2025-01-10 [1] CRAN (R 4.4.2)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.4.2)
#>  fs            1.6.5   2024-10-30 [1] CRAN (R 4.4.2)
#>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.4.2)
#>  htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.4.2)
#>  knitr         1.49    2024-11-08 [1] CRAN (R 4.4.2)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.4.2)
#>  reprex        2.1.1   2024-07-06 [1] CRAN (R 4.4.2)
#>  rlang         1.1.4   2024-06-04 [1] CRAN (R 4.4.2)
#>  rmarkdown     2.29    2024-11-04 [1] CRAN (R 4.4.2)
#>  rstudioapi    0.17.1  2024-10-22 [1] CRAN (R 4.4.2)
#>  sessioninfo * 1.2.2   2021-12-06 [1] CRAN (R 4.4.2)
#>  withr         3.0.2   2024-10-28 [1] CRAN (R 4.4.2)
#>  xfun          0.50    2025-01-07 [1] CRAN (R 4.4.2)
#>  yaml          2.3.10  2024-07-26 [1] CRAN (R 4.4.1)
#> 
#>  [1] C:/Program Files/R/R-4.4.2/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Created on 2025-01-13 with reprex v2.1.1

@juliasilge
Copy link
Member

juliasilge commented Jan 13, 2025

Here is a simpler reprex, as found in posit-dev/positron#5969:

reprex::reprex({
	x <- rnorm(100)
	plot(x, sin(x))
	})

If you look at std_out, it's failing to upload the image to imgur:

Standard output and error

Quitting from lines 20-22 [unnamed-chunk-2] (steep-carp_reprex.spin.Rmd)
Error in xfun::upload_imgur(file, key, ..., include_xml = TRUE) : 
  Failed to upload steep-carp_reprex_files/figure-gfm/unnamed-chunk-2-1.png (reason: 1025)

I will highlight that there was a brand new release of xfun a few days ago.

@jennybc
Copy link
Member

jennybc commented Jan 14, 2025

The full story is at yihui/xfun#97. The key used for imgur uploads, which any reprex with a plot will tickle, by default, is out of service, with "too many requests". It's unclear why or if the situation is permanent.

So I'll keep an eye on this for a bit. If fortune smiles, the key will start working again, maybe after some suitable period of time has passed. Otherwise, we'll have to take some more measures to use a different key or make it more obvious to reprex users how to provide their own key.

@jennybc jennybc changed the title Simple code block crashes {reprex} R session. reprex with a plot fails (because imgur upload fails due to the API key quota being exhausted) Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants