I have my code below that I am using to generate multiple fasta files from an alignment and a tree. I would like to write these multiple fasta files in individual directories, but my code is writing the folder and file side by side, instead of writing the file inside the folder. Thank you in advance.
l = 182
i = 1
repeat {
a = (tree[[i]]$tip.label) #sequences names
b = div_seqs[names(div_seqs) %in% a] #sequences
mylabel <- "seqs"
tempdir = dir.create(paste0(mylabel, "_", i))
myfile <- (paste0(mylabel, "_", i, ".fas"))
file.path(tempdir(), write.fasta(b, a, file = myfile, open = "w", nbchar = 600, as.string = FALSE))
i = i+1
if (i==l+1){
break
}
} ```