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

Error in if (n == 1) word else paste(word, "s", sep = "") : the condition has length > 1 #1655

Closed
idavydov opened this issue Aug 18, 2023 · 6 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@idavydov
Copy link

idavydov commented Aug 18, 2023

I have a project with renv 1.0.2. It seems to work fine in one environment, but inside a docker image it generates the following error when R is starting:

renv::restore()
$ Rscript -e 'renv::restore()'
# Bootstrapping renv 1.0.2 ---------------------------------------------------
- Downloading renv ... OK
- Installing renv  ... OK
- One or more packages recorded in the lockfile are not installed.
- Use `renv::status()` for more details.
The following package(s) will be updated:
...
The following loaded package(s) have been updated:
- BiocManager
Restart your R session to use the new versions.
Warning message:
failed to resolve remote 'GuangchuangYu/treeio'; skipping 
$ R -e 'bookdown::render_book( "index.Rmd", "bookdown::gitbook", output_dir = "public" )'
R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
  Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
- Project '/builds/PMDA/training/the_book_of_flowers' loaded. [renv 1.0.2]
Error in if (n == 1) word else paste(word, "s", sep = "") : 
  the condition has length > 1
Calls: source ... sprintf -> <Anonymous> -> nplural -> paste -> plural
In addition: Warning messages:
1: In if (grepl("-display$", label)) return(TRUE) :
  the condition has length > 1
2: In if (grepl("-display$", label)) return(TRUE) :
  the condition has length > 1
Execution halted

I tried to add the following lines to the beginning of the .Rprofile:

options(error = renv:::renv_error_handler_call()); options(warn = 2L); "

Then the error looks like this (no change, it seems):

$ R -e 'bookdown::render_book( "index.Rmd", "bookdown::gitbook", output_dir = "public" )'
R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
  Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
- Project '/builds/PMDA/training/the_book_of_flowers' loaded. [renv 1.0.2]
Error in if (grepl("-display$", label)) return(TRUE) : 
  (converted from warning) the condition has length > 1
Calls: source ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
> bookdown::render_book( "index.Rmd", "bookdown::gitbook", output_dir = "public" )
Error in if (grepl("-display$", label)) return(TRUE) : 
  (converted from warning) the condition has length > 1
Calls: source ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
@kevinushey
Copy link
Collaborator

Are you able to share the contents of your bookdown project? This error:

Error in if (grepl("-display$", label)) return(TRUE) : 
  (converted from warning) the condition has length > 1

seems to imply you have a chunk with multiple labels, or that renv failed to parse the label in one of your chunks.

@idavydov
Copy link
Author

It took a bit of time to debug this.

Turns out, I forgot to include renv cache directory to .gitignore. Since the thing was running inside CI, it's quite common to have CI directory as a sub-directory inside the repository. So renv was searching for dependencies across several hundred cached packages.

Now the questions are:

  • Is it worth it so search which file broke renv dependency search?
  • Or would it be maybe more useful to report a file where parsing broke?
  • Maybe renv could automatically exclude the cache directory from search?

@kevinushey
Copy link
Collaborator

Thanks! Maybe renv should drop a .renvignore file in the cache directory?

@idavydov
Copy link
Author

idavydov commented Aug 23, 2023

.renvignore in the cache directory seems like a great idea to me.

@DaboinCJ
Copy link

Hi @idavydov,

I'm getting the same error message while deploying a Shiny App to Heroku 20 using Heroku buildpack-r.

Can you describe how you solved it? What changes did you make to the .gitignore?

Thank you

@idavydov
Copy link
Author

hi @DaboinCJ , in my case library cache location was set up using:

RENV_PATHS_CACHE: "$PROJECT_DIR/ci/renvcache"

So I simply added ci to .gitignore to make sure that renv doesn't scan the cache.

Does that help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants