Skip to content

Commit

Permalink
fixup for non-scalar plural usages (#1733)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Oct 18, 2023
1 parent 1f5bafc commit 4b11818
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# renv (development version)

* Fixed an issue where directories containing a large number of files could
cause `renv` to fail to activate a project. (#1733)

* Expanded the set of Linux distributions detected for automatic transformation
of Posit Package Manager URLs to install binary packages. `renv` now correctly
detects Red Hat Enterprise Linux 9, Rocky Linux 8 and 9, SLES 15 SP4 and SP5,
Expand Down
4 changes: 3 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ read <- function(file) {
}

plural <- function(word, n) {
if (n == 1) word else paste(word, "s", sep = "")
suffixes <- c("", "s")
indices <- as.integer(n != 1L) + 1L
paste0(word, suffixes[indices])
}

nplural <- function(word, n) {
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,15 @@ test_that("warnify() propagates errors as warnings", {
expect_equal(result, "warning")

})

# https://github.com/rstudio/renv/issues/1733
test_that("plural() and nplural() handle non-scalar counts", {

actual <- plural("file", 0:3)
expected <- c("files", "file", "files", "files")
expect_equal(actual, expected)

actual <- nplural("file", 0:3)
expected <- c("0 files", "1 file", "2 files", "3 files")
expect_equal(actual, expected)
})

0 comments on commit 4b11818

Please sign in to comment.