You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clarify the difference between style_pkg() and style_dir(). #293
When working on #291, @jonmcalder and me were wondering about how style_dir() and style_pkg() should differ given that we now also support .Rmd. I think initially, the idea was to style R/, and tests/testthat/ for packages and not styling R/RcppExports.R. style_dir() should style any code file in the directory. @krlmlr any ideas how we can make the distinction clear before the CRAN release? I think with style_pkg() we wanted to avoid styling by-products, e.g. built vignette code (both .R and .Rmd).
It was me that raised the question initially, so happy to weigh in here and then @lorenzwalthert can clarify as necessary. Essentially my question is why we have two separate functions for this? As Lorenz says above, the current intention is for style_dir() to style everything (R and/or Rmd files) indiscriminately whereas style_pkg() should style R files (and/or Rmd files after addressing the rest of #291) in specific sub-directories with specific exclusions (e.g. RcppExports.R). Both function definitions also already allow for (additional) manual file exclusions.
Since the functions are very similar I was wondering whether it might make sense to generalize style_dir() to handle the style_pkg() case automatically by identifying whether a directory is a package directory? I think this would simplify the API and also ties in to some extent with what was discussed in #250. I may be overlooking potential negative side effects/complications here though.
This only really came up because we were looking to minimize repetition/redundancy in the process of #291 / #292.
I think one important question is which .Rmd files should get styled with style_pkg()? E.g. including the vignettes in vignettes? What about other files in directories other than R or tests/testthat? Currently we style tests/testtthat if I remember correctly, but why not all tests in test?
I prefer two separate entry points. We might be able to eliminate redundancy if each function collects the files to be styled beforehand and then calls style_file().
Styling all files in tests/ is a good idea, because testthat might change its file layout in the future. We might also want to look for .Rmd files in subdirectories of vignettes/, and perhaps also README.Rmd. The R/ directory can have subdirectories, too (unix/ and win/ currently). The data-raw/ directory is another candidate for styling, but not terribly important. We can always add more to style_pkg() later.
Ok sure. So then can't prettify_local() just be replaced by a call to prettify_any() with additions to the exclude_files argument as necessary (e.g. R/RcppExports.R)?
That would eliminate some of the redundancy, but I suppose the call to dir() with recursive = TRUE is fairly inefficient when you know you only want to style specific sub-directories...
Activity
krlmlr commentedon Nov 27, 2017
The distinction seems clear enough to me -- if it's a package, use
style_pkg(), otherwise usestyle_dir(). What do you think are we missing?jonmcalder commentedon Nov 27, 2017
It was me that raised the question initially, so happy to weigh in here and then @lorenzwalthert can clarify as necessary. Essentially my question is why we have two separate functions for this? As Lorenz says above, the current intention is for
style_dir()to style everything (R and/or Rmd files) indiscriminately whereasstyle_pkg()should style R files (and/or Rmd files after addressing the rest of #291) in specific sub-directories with specific exclusions (e.g. RcppExports.R). Both function definitions also already allow for (additional) manual file exclusions.Since the functions are very similar I was wondering whether it might make sense to generalize
style_dir()to handle thestyle_pkg()case automatically by identifying whether a directory is a package directory? I think this would simplify the API and also ties in to some extent with what was discussed in #250. I may be overlooking potential negative side effects/complications here though.This only really came up because we were looking to minimize repetition/redundancy in the process of #291 / #292.
lorenzwalthert commentedon Nov 27, 2017
I think one important question is which
.Rmdfiles should get styled withstyle_pkg()? E.g. including the vignettes invignettes? What about other files in directories other than R ortests/testthat? Currently we styletests/testtthatif I remember correctly, but why not all tests intest?krlmlr commentedon Nov 27, 2017
I prefer two separate entry points. We might be able to eliminate redundancy if each function collects the files to be styled beforehand and then calls
style_file().Styling all files in
tests/is a good idea, because testthat might change its file layout in the future. We might also want to look for.Rmdfiles in subdirectories ofvignettes/, and perhaps alsoREADME.Rmd. TheR/directory can have subdirectories, too (unix/andwin/currently). Thedata-raw/directory is another candidate for styling, but not terribly important. We can always add more tostyle_pkg()later.jonmcalder commentedon Nov 27, 2017
Ok sure. So then can't
prettify_local()just be replaced by a call toprettify_any()with additions to theexclude_filesargument as necessary (e.g.R/RcppExports.R)?That would eliminate some of the redundancy, but I suppose the call to
dir()withrecursive = TRUEis fairly inefficient when you know you only want to style specific sub-directories...lorenzwalthert commentedon Nov 27, 2017
So to sum it up, we have for
style_pkg():Must work also if directory does not exists. Correct if I missed something. Plus it should also be stated in the help file which files are styled.
lorenzwalthert commentedon Nov 27, 2017
I like the idea of collecting and then using
style_file().krlmlr commentedon Nov 27, 2017
R/,tests/anddata-rawshouldn't have.Rmdfiles.lorenzwalthert commentedon Nov 27, 2017
Ok, so we can agree not to look for them there 😊
krlmlr commentedon Dec 5, 2017
Closed by #292.