Skip to content

Commit

Permalink
Merge pull request #342 from etiennebacher/speedup-iso
Browse files Browse the repository at this point in the history
Faster conversion from all codes (not country names)
  • Loading branch information
vincentarelbundock authored Sep 8, 2023
2 parents 7342335 + efa0ff6 commit 848e9ce
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/countrycode.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ countrycode <- function(sourcevar, origin, destination, warn = TRUE, nomatch = N
if(is.null(custom_dict)){ # only for built-in dictionary
# unicode.symbol breaks uppercase on Windows R-devel 2022-02-02; rejected by CRAN
if(inherits(origin_vector, 'character') & !grepl('country|unicode.symbol', origin)){
origin_vector = toupper(origin_vector)
# only apply toupper() on unique values and match after.
# much faster than applying toupper() on the whole vector
# when vector is very large
uniques <- unique(origin_vector)
uppercase <- toupper(uniques)
origin_vector <- unname(uppercase[match(origin_vector, uniques)])
}
}

Expand Down

0 comments on commit 848e9ce

Please sign in to comment.