tidyverse / reprex

Render bits of R code for sharing, e.g., on GitHub or StackOverflow.
https://reprex.tidyverse.org
Other
741 stars 80 forks source link

Warning exists when `reprex(... style = FALSE)` #461

Closed beauchamplab closed 4 months ago

beauchamplab commented 9 months ago

With style=FALSE, users would like to render without styler. I wonder if "Install the styler package" should still show up?

reprex::reprex({ print("") }, style = FALSE)
#> ✖ Install the styler package in order to use `style = TRUE`.
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> ℹ Rendering reprex...

Created on 2024-02-02 with reprex v2.1.0

jennybc commented 9 months ago

Yeah this appears to be a thinko in this helper. It doesn't seem to consult whether style is TRUE or FALSE 🙈

https://github.com/tidyverse/reprex/blob/e1f65e9949ed30d1ee4f1e984736b408d8e001ee/R/reprex_impl.R#L129-L137

beauchamplab commented 9 months ago

Our users asked us if they should install styler since they got this "warning". Maybe:

style_requires_styler <- function(style) { 
   if (style && !requireNamespace("styler", quietly = TRUE)) { 
     reprex_danger(" 
       Install the {.pkg styler} package in order to use 
       {.code style = TRUE}.") 
     style <- FALSE 
   } 
   invisible(style) 
 } 

?

jennybc commented 9 months ago

Yes LGTM. Would you like to make a PR?