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

allow renv ignores to be set via option #866

Merged
merged 1 commit into from
Nov 16, 2021

Conversation

kevinushey
Copy link
Collaborator

@kevinushey kevinushey commented Nov 12, 2021

Closes #863.

This PR allows one to set .renvignore-style ignores for renv via the option renv.renvignore.exclude. These can either be .gitignore-style ignores, or (if the asis attribute is set to TRUE) PCREs which match against the full file path. (Directories will have a trailing / appended to the path.)

The option is primarily intended for internal consumption, so I haven't documented any explicit interface here.

I think the usage for Packrat here would be something like:

# get ignores
ignores <- packrat::opts$ignored.directories()

# post-process ignore in some appropriate way

# tell renv to use the pattern as-is
attr(ignores, "asis", TRUE) <- TRUE

# set the option
options(renv.renvignore.exclude = ignores)

Let me know if this seems sane.

Copy link
Contributor

@aronatkins aronatkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change appears to work on my end.

Code like the following converts from the ignored.directories setting to an renv ignore pattern:

ignoresForRenv <- function(ignoredDirectories) {
  ignores <- NULL
  if (length(ignoredDirectories) > 0) {
    ignores <- ignoredDirectories
    # Make sure all the directories end with a slash.
    ignores <- ifelse(
        substr(ignores, nchar(ignores), nchar(ignores)) != "/",
        paste0(ignores, "/"),
        ignores
    )
    # Make sure all the directories begin with a slash.
    ignores <- ifelse(
        substr(ignores, 1, 1) != "/",
        paste0("/", ignores),
        ignores
    )
    attr(ignores, "asis") <- TRUE
    cat(paste0("renv ignore: ", ignores), sep = "\n")
  }
  ignores
}

That then feeds into an option-set:

  old_renv_exclude <- options("renv.renvignore.exclude" = ignoresForRenv(opts$ignored.directories()))
  on.exit(do.call(options, old_renv_exclude), add = TRUE)

One thing I had not done previously was forcing the same path and root for renv::dependencies; most of my previous experimentation left root = NULL (but I had been careful to setwd). With this set of changes, I have all tests passing.

aronatkins added a commit to rstudio/packrat that referenced this pull request Nov 16, 2021
@kevinushey kevinushey merged commit 0f57a1f into main Nov 16, 2021
aronatkins added a commit to rstudio/packrat that referenced this pull request Nov 17, 2021
aronatkins added a commit to rstudio/packrat that referenced this pull request Dec 20, 2021
@hadley hadley deleted the feature/renvignore-pattern-options branch May 5, 2023 12:10
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

Successfully merging this pull request may close these issues.

option for ignore rules
2 participants