Skip to content

Commit

Permalink
bug apply simplify in older R versions
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Apr 2, 2024
1 parent 7d3b82d commit 29b5b34
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: countrycode
Title: Convert Country Names and Country Codes
Version: 1.6.0
Version: 1.6.0.9000
Authors@R:
c(person(given = "Vincent",
family = "Arel-Bundock",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# News

## development

* The `simplify` argument in `apply` was introduced in R 4.1.0. We used it, which broke usage of countrycode on older versions of R.

## countrycode 1.6.0

* Important speed-up for detection of country names using regular expressions (Thanks to Etienne Bacher).
Expand Down
8 changes: 7 additions & 1 deletion R/countrycode.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ countrycode_convert <- function(# user-supplied arguments
if (all(is.na(choices))) {
matches <- vector("list", length = length(choices))
} else {
out <- apply(matchidx, 1, which, simplify = FALSE)
# Issue reported to Vincent by email
# simplify=FALSE was introduced in R 4.1.0. we want coverage before
# out <- try(apply(matchidx, 1, which, simplify = FALSE))
out <- apply(matchidx, 1, which)
if (length(out) == 0) {
out <- rep(list(NULL), nrow(matchidx))
}
names(out) <- choices
matches <- lapply(out, function(x) dict[x, destination])
}
Expand Down

0 comments on commit 29b5b34

Please sign in to comment.