Hi Karen, You can use R's gsub function to do this. gsub replaces all occurrences of a pattern(not just the first one, like sub) and you can use Regular Expressions to match anything between ")" and ":" or ";". You can try this out:
gsub("(?<=\\)).*?(?=\\:|\\;)", "", my_newick_string, perl=T) Have a nice day, - Christie On Mon, Aug 24, 2015 at 1:35 PM, Karen Gordon <k_gor...@sfu.ca> wrote: > Hi There, > > I’m currently wanting to make some changes to some phylogenies in R by > reading in the newick text as a string, rather than as a phylo object. The > reason is that the trees are large (~10,000 tips and another set with ~5000 > tips) and I must make changes to a complete set of these tree (i.e. 10,000 > trees). Currently, these trees have node labels, which I’d like to remove. > > Essentially what I’d like to do is substitute “)?:” with “):” or simply > delete "?", where “?" is any and all characters that occur between the > “close” parenthesis and the colon. So far I found I could use the function > ’sub’ but I’d like to make the replacements in one fell swoop, without > knowing what the node labels are in advance. Also the sub function seems > to only replace the first occurrence of the pattern rather than all matches > in a string. Any suggestions would be greatly appreciated! Thank you! > > best, > Karen > > _______________________________________________ > R-sig-phylo mailing list - R-sig-phylo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > Searchable archive at > http://www.mail-archive.com/r-sig-phylo@r-project.org/ > [[alternative HTML version deleted]] _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/