Permutations with repetitions algorithm in R
This is one of many instances where people would be tempted to say, "see, loops in R are slow".  And my response is, "loops aren't that slow, but you can put slow code in loops."

There's no reason res needs to be a data.frame.  Leave it as a matrix and your code runs in under a second on my laptop.

# initialize res
res &lt;- matrix(rep(NA,totCombs*totChars),ncol=totChars)


The lesson here is:


  If you don't need the multi-typed columns of a data.frame, use a matrix.




You might look into factoradics as another possible algorithm. That would allow you to generate permutations in lexicographic order.