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

{styler} removed? #168

Open
lorenzwalthert opened this issue Jun 11, 2021 · 7 comments
Open

{styler} removed? #168

lorenzwalthert opened this issue Jun 11, 2021 · 7 comments

Comments

@lorenzwalthert
Copy link

lorenzwalthert commented Jun 11, 2021

Hi, thanks for this cool package. I saw you removed {styler} in 2f86db9.

  • As the maintainer of {styler}, I am curious to learn more about the reasons why you removed it.
  • As a user, I can't use {styler} anymore. This seems like a hard cut. Is there a way to optionally use styler, e.g. governed by an environment variable R option? Then, people could either opt in or opt out of styling.
@pvictor
Copy link
Member

pvictor commented Jul 5, 2021

Hello,
Yes {styler} is a very good package, I use it regularly. The problem here, reported by some users, was with the R cache folder, where it blocked the ggplot2 code generated to be displayed in the addin and further use of the addin itself. For new users this is very confusing, so I chose to use a minimal formating of the code in the addin and to recommend to use {styler} after that in R scripts.

In a future realease, I want to integrate a feature to display history of code generated (so potentially more code), maybe I'll use {styler} then, it will be more robust than my current solution.
And I kinda like Garrick style (https://github.com/gadenbuie/grkstyle), so I've to look closer how all this works.

Victor

@lorenzwalthert
Copy link
Author

Thanks for the explanation. You are not the first to explore this problem unfortunately. A simple workaround to disable the prompt is to use a temporary cache location (instead of one persisting over multiple sessions) by setting an environment variable. It's described here:

https://styler.r-lib.org/reference/caching.html#non-interactive-setup

Bottom line for you:

# temporary set env variable for call to styler.
withr::with_envvar(
  R_CACHE_ROOTPATH = file.path(tempdir(), 'R.cache.esquisse'), 
  styler::style_text(...)
)

Note that this does not add a new dependency to your probject because {withr} is already an indirect dependency (via {shiny} and other packages you import).

Also, maybe once HenrikBengtsson/R.cache#43 is merged and CRAN-released, you could do this:

# temporary set env variable for call to styler.
withr::with_envvar(
  R_CACHE_ROOTPATH_ASK = FALSE 
  styler::style_text(...)
)

If you want to use Garrick over tidyverse style, note that the {R.cache} behavior is the same, because Garrick provides only a style guide (=rules for styling), {styler} provides not just the tidyverse style guide but also the mechanism to format code according to arbitrary style guides.

Happy to assist if you have further questions.

@HenrikBengtsson
Copy link

HenrikBengtsson commented Jul 7, 2021

See my HenrikBengtsson/R.cache#43 (comment) comment; per CRAN policies R.cache (>= 0.15.0) no longer have to ask for permission to create it's cache folders as long as they're in a standard location, so there should be no prompt.

@lorenzwalthert
Copy link
Author

Thanks @HenrikBengtsson. I'll add a minimum version requirement for R.cache in r-lib/styler#819. @pvictor this means once this new styler version is released (assuming you want to add {styler} again), just require this minimal version and blocking prompt problem should be resolved.

@lorenzwalthert
Copy link
Author

@pvictor {styler} 1.5.1 is released, where the minimal version requirement for {R.cache} is included, so you could just require styler >= 1.5.1 in your package to get rid of the problems.

@lorenzwalthert
Copy link
Author

@pvictor, as stated above, the problems related to {styler} are now resolved. Would you consider re-adding it?

@pvictor
Copy link
Member

pvictor commented Jan 10, 2022

Thanks for the heads up @lorenzwalthert , I'll look into that

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