r-lib / styler

Non-invasive pretty printing of R code
https://styler.r-lib.org
Other
713 stars 70 forks source link

standalone files imported from other packages should be ignored in `style_pkg()` #1134

Closed olivroy closed 11 months ago

olivroy commented 1 year ago

Hi,

I think that standalone files from core tidyverse packages should be ignored from styling. At the moment, the default values for exclude_files is c("R/RcppExports.R", "R/cpp11.R"), but I think it could be c("R/RcppExports.R", "R/cpp11.R", "R/import-standalone-*")

or a new argument exclude_import_standalone that would default to TRUE.

If you are not familiar with the new standalone files, here are some references

https://usethis.r-lib.org/reference/use_standalone.html

https://github.com/r-lib/rlang/blob/main/R/standalone-types-check.R

A PR in dplyr where they use it tidyverse/dplyr#6722. They also use it in ggplot2

In a package, if I use

usethis::use_standalone("r-lib/rlang", "types-check")
The file will be copied to `mypkg/R/important-standalone-type-check.R`
# it will be read-only.
# but when I run, `styler::style_pkg()`, it will restyle the file.

I think that because these files appear as read-only in RStudio. If they are to be styled, they should be styled in the original repos (in this case in rlang)

lorenzwalthert commented 1 year ago

Ok I see. I agree these should probably not be styled by default. A simple way to do that would be to make exclude_files take regex patterns instead of file names. We could adapt the default value such that the behavior is the same as now. Are you interested in making a PR? I can provide guidance.

olivroy commented 1 year ago

Hi, I am not sure I have a lot of time.

I don't mind opening a preliminary version. but first thoughts

Here is my initial work

https://github.com/olivroy/styler/commit/e24dc6812316ba0cb7506a4978ac0f27a163571f

I don't mind opening a PR, but I will not have time to review / readjust it in the coming days.