tree <- rtree(10)
dat <- simSeq(tree, l=24)
fcat <- function(..., file = zz) cat(..., file=file, sep="", append=TRUE)
zz <- tempfile(pattern="file", tmpdir=tempdir(), fileext=".nex")
write.phyDat(dat, file=zz, format="nexus")
fcat("BEGIN SETS;\n")
fcat(" Charset codon1 = 1-12/3;\n")
fcat(" Charset codon2 = 2-12/3;\n")
fcat(" Charset codon3 = 3-12/3;\n")
fcat(" Charset range = 16-18;\n")
fcat(" Charset range2 = 13-15 19-21;\n")
fcat(" Charset singles = 22 23 24;\n")
fcat("END;\n")
tmp <- read.nexus.partitions(zz)
tmp
unlink(zz)
Run the code above in your browser using DataLab