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

Dependency discovery trips on multiple directories having many files #1733

Closed
psanker opened this issue Oct 18, 2023 · 4 comments
Closed

Dependency discovery trips on multiple directories having many files #1733

psanker opened this issue Oct 18, 2023 · 4 comments

Comments

@psanker
Copy link

psanker commented Oct 18, 2023

Hello,

I found a vexing little bug that should be easy to fix. Upon activating an renv project (version 1.0.3), renv does its normal routine of dependency discovery to crosscheck against the lockfile. If, say, you have multiple nested subdirectories that each contain hundreds of files, renv throws a warning message:

# At 'R/snapshot.R#957'
# 
# report to user
lines <- c(
  "",
  "NOTE: Dependency discovery took %s during snapshot.",
  "Consider using .renvignore to ignore files, or switching to explicit snapshots.",
  "See `?renv::dependencies` for more information.",
  if (length(count)) c(
    "",
    sprintf("- %s: %s", format(names(count)), nplural("file", count))
  ),
  ""
)

If there are multiple directories that are in count, then this should be a multi-length vector. This is all fine and dandy, but there is a lurking issue: nplural. nplural in turn calls plural with its source being:

# R/utils.R#243
plural <- function(word, n) {
  if (n == 1) word else paste(word, "s", sep = "")
}

This now will throw an error when length(n) > 1. As it exists now, renv crashes on activation, which means any related processes (e.g. {languageserver}) will also crash when trying to operate on the project files.

I would amend this utility to:

plural <- function(word, n) {
  stopifnot(length(word) == length(n))
  
  if (length(word) > 1) {
    # Assuming compat-purrr or equivalent is around; I didn't check
    return(map2_chr(word, n, plural))
  }

  if (n == 1) word else paste(word, "s", sep = "")
}

Would be happy to create a PR for this!

@kevinushey
Copy link
Collaborator

Thank you for the diagnosis; it's hugely appreciated! A number of users have bumped into this as well. I'll take a look.

@kevinushey
Copy link
Collaborator

I pushed a similar fix to the development version of renv; would you be able to test and confirm if that helps?

@psanker
Copy link
Author

psanker commented Oct 19, 2023

Seems to work!

@kevinushey
Copy link
Collaborator

Great, thanks!

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

2 participants