I have the following code that generate the unique permutation:
library(magrittr)
library(tictoc)
count_unique_perm <- function(l = NULL) {
lo <- combinat::permn(l)
do.call(rbind, lapply(lo, paste0, collapse = ""))[, 1] %>%
unique() %>%
length()
}
It already give the correct result. With this input:
l1 <- c("R", "R", "R", "R", "R", "R", "R", "E", "K", "P") # 720
l2 <- c("R", "R", "R", "R", "R", "Q", "G", "K", "M", "S") # 30,240
But it's running extremely slow.
tic()
count_unique_perm(l = l1)
toc()
#118.155 sec elapsed
#107.793 sec elapsed for l2
How can I speed it up?