From 29b5b342ae4c793201bdcefdf71aeb95ceb218e1 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Tue, 2 Apr 2024 16:37:31 -0400 Subject: [PATCH] bug apply simplify in older R versions --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/countrycode.R | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c3f4fa6..bd4e8f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/NEWS.md b/NEWS.md index a30ea8f..981e8dd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/R/countrycode.R b/R/countrycode.R index 967c640..a01aba3 100644 --- a/R/countrycode.R +++ b/R/countrycode.R @@ -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]) }