# Create example matrix
example_matrix <- paste("#NEXUS", "", "BEGIN DATA;",
"\tDIMENSIONS NTAX=5 NCHAR=5;",
"\tFORMAT SYMBOLS= \" 0 1 2\" MISSING=? GAP=- ;",
"MATRIX", "", "Taxon_1 010?0", "Taxon_2 021?0",
"Taxon_3 02111", "Taxon_4 011-1",
"Taxon_5 001-1", ";", "END;", "",
"BEGIN ASSUMPTIONS;",
"\tOPTIONS DEFTYPE=unord PolyTcount=MINSTEPS ;",
"\tTYPESET * UNTITLED = unord: 1 3-5, ord: 2;",
"\tWTSET * UNTITLED = 1: 2, 2: 1 3-5;",
"END;", sep = "\n")
# Write example matrix to current working directory called
# "morphmatrix.nex":
cat(example_matrix, file = "morphmatrix.nex")
# Read in example matrix:
morph.matrix <- read_nexus_matrix("morphmatrix.nex")
# View example matrix in R:
morph.matrix
# Remove the generated data set:
file.remove("morphmatrix.nex")
Run the code above in your browser using DataLab