Skip to content

Commit

Permalink
Use unlist()/relist() strategy
Browse files Browse the repository at this point in the history
3x faster than the previous commit
  • Loading branch information
Bisaloo committed Jul 27, 2024
1 parent 53ab635 commit 7a23c84
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/numberize.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ digits_from <- function(text, lang = "en") {
}

words <- strsplit(text, "\\s+")
digits <- lapply(words, function(w) {
base_numbers[match(w, base_numbers[[lang]]), "digit"]
})
digits

# It's faster to unlist()/relist() than looping over the list
digits <- base_numbers[match(unlist(words), base_numbers[[lang]]), "digit"]
relist(digits, words)
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 7a23c84

Please sign in to comment.