Skip to content

Commit

Permalink
save some memory
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Sep 7, 2023
1 parent ee22389 commit 43e4970
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/countrycode.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ countrycode <- function(sourcevar, origin, destination, warn = TRUE, nomatch = N
# unicode.symbol breaks uppercase on Windows R-devel 2022-02-02; rejected by CRAN
if(inherits(origin_vector, 'character') & !grepl('country|unicode.symbol', origin)){
# only apply toupper() on unique values and match after.
# much faster than applying toupper() on the whole vector when vector is very large
# much faster than applying toupper() on the whole vector
# when vector is very large
uniques = unique(origin_vector)
uppercase = toupper(uniques)
names(uppercase) = uniques
origin_vector = unname(uppercase[match(origin_vector, names(uppercase))])
origin_vector = unname(uppercase[match(origin_vector, uniques)])
}
}

Expand Down

0 comments on commit 43e4970

Please sign in to comment.