Some software can occasionally insert line breaks when exporting alignments (in this case morphological data alignments). Finding and fixing them can be frustrating and tedious. This function quickly removes line breaks from a specified alignment, allowing it to be read into R. An example of the problem:

library(Claddis)
align <- ReadMorphNexus("export2.nex")
#> Error in ReadMorphNexus("export2.nex"): Some matrix block(s) have too many or too few taxa. Check for linebreaks or incorrect NTAX value.

The first argument of the function fixLineBreaks is a character string of length 1 specifyig the file name of interest. The second argument is a character string of length 1 specifying the desired file output name.

library(dplyr)
library(ape)
source("fixLineBreaks.R")
fixLineBreaks("export2.nex", outputname = "lineFix")

The function will have exported a file called \(lineFix.nex\), to which the \(FORMAT\) line you need to manually add \(symbols="0123456789"\), but then you should be able to load the file no problem

align <- ReadMorphNexus("lineFix.nex")

NOTE: if the species/sample names in the alignment end with a number or a parentheses then this function will not work, so be careful there! The function itself is found here. The file contains a few functions, some of which might be useful on their own. For example fix.polymorphism makes sure that polymorphisms are treated appropriately in a character string

string <- c("0","1","1","(","1","2","3",")","1")
fix.polymorphism(string)
#> [1] "0"     "1"     "1"     "(123)" "1"