Skip to content

Clarify the difference between style_pkg() and style_dir().  #293

Closed

Description

@lorenzwalthert

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).

Related: #250.

Activity

  1. krlmlr commented on Nov 27, 2017

    @krlmlr
    Member

    The distinction seems clear enough to me -- if it's a package, use style_pkg(), otherwise use style_dir(). What do you think are we missing?

  2. jonmcalder commented on Nov 27, 2017

    @jonmcalder
    Contributor

    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.

  3. lorenzwalthert commented on Nov 27, 2017

    @lorenzwalthert
    CollaboratorAuthor

    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?

  4. krlmlr commented on Nov 27, 2017

    @krlmlr
    Member

    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.

  5. jonmcalder commented on Nov 27, 2017

    @jonmcalder
    Contributor

    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...

  6. lorenzwalthert commented on Nov 27, 2017

    @lorenzwalthert
    CollaboratorAuthor

    So to sum it up, we have for style_pkg():

    • README.Rmd (case insensitive).
    • all R files in tests/ recursively.
    • all R files in R/ recursively except R/RcppExports.R.
    • all R files in data-raw / recursively.
    • all Rmd files in vignettes/ recursively.

    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.

  7. lorenzwalthert commented on Nov 27, 2017

    @lorenzwalthert
    CollaboratorAuthor

    I like the idea of collecting and then using style_file().

  8. krlmlr commented on Nov 27, 2017

    @krlmlr
    Member

    R/, tests/ and data-raw shouldn't have .Rmd files.

  9. lorenzwalthert commented on Nov 27, 2017

    @lorenzwalthert
    CollaboratorAuthor

    Ok, so we can agree not to look for them there 😊

  10. krlmlr commented on Dec 5, 2017

    @krlmlr
    Member

    Closed by #292.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions