R code to produce permutations