<p>I cannot access the book, it might be an older version or there are some steps in between. The screen shot doesn't help.</p>
<p>If you look at the <a href="https://cran.r-project.org/web/packages/phangorn/vignettes/phangorn-specials.pdf" rel="nofollow noreferrer">vignette</a> and the error, what you need to provide is a matrix of characters with defined row names, for example:</p>
<pre><code>set.seed(111)
x = sample(letters,100,replace=TRUE)
phyDat(matrix(x),&quot;USER&quot;,levels=unique(x))

Error in phyDat.default(data, levels = levels, return.index = return.index,  : 
  data object must contain taxa names

mat = matrix(x,10,10,dimnames=list(paste0(&quot;t&quot;,1:10),NULL))
phyDat(mat,&quot;USER&quot;,levels=unique(x))
10 sequences with 10 character and 10 different site patterns.
The states are n t s o y e c h z q m j d o h n z y x p q g u o a i h y c g t d f y t d f e u e f d i j r z x w u m a j p j g d t q y v o x p m s o z x z a y j z r u s a y k l f g l f r i l r f m t t e f x v f g q j 
</code></pre>

CC BY-SA 4.0
2020-08-12T19:49:29.510Z
2020-08-12T19:49:29.510Z
StupidWolf
<p>I am following an example from ‘Analysis of Phylogenetics Second Edition and Evolution with R’ from Emmanuel Paradis.</p>
<p>He is doing:</p>
<p><a href="https://i.sstatic.net/7uTVB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7uTVB.png" alt="enter image description here" /></a></p>
<p>I am doing pretty much the same:</p>
<pre><code>x=c('garras','garras','garras', 'tejido','tejido','tejido')
y &lt;- phyDat(matrix(x), &quot;USER&quot;, levels = unique(x))
</code></pre>
<p>but I get:</p>
<blockquote>
<p>Error in phyDat.default(data, levels = levels, return.index =
return.index, : data object must contain taxa names</p>
</blockquote>
<p>Screenshot:</p>
<p><a href="https://i.sstatic.net/bIRKC.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bIRKC.png" alt="enter image description here" /></a></p>
<p>What am I doing wrong? how come the example from the book works...</p>

<r><phylogenetics>
Unable to use phangorn::phyDat
# Unable to use phangorn::phyDat

(Asked by: username_0 on 2020-08-11)

I am following an example from ‘Analysis of Phylogenetics Second Edition and Evolution with R’ from Emmanuel Paradis.
He is doing:

I am doing pretty much the same:
x=c('garras','garras','garras', 'tejido','tejido','tejido')
y <- phyDat(matrix(x), "USER", levels = unique(x))

but I get:

Error in phyDat.default(data, levels = levels, return.index =
return.index, : data object must contain taxa names

Screenshot:

What am I doing wrong? how come the example from the book works...

**Tags:** r, phylogenetics

---

## 1 answers

### Answer by username_1 on 2020-08-12. Score: 1 | Accepted answer

I cannot access the book, it might be an older version or there are some steps in between. The screen shot doesn't help.
If you look at the vignette and the error, what you need to provide is a matrix of characters with defined row names, for example:
set.seed(111)
x = sample(letters,100,replace=TRUE)
phyDat(matrix(x),"USER",levels=unique(x))

Error in phyDat.default(data, levels = levels, return.index = return.index,  : 
  data object must contain taxa names

mat = matrix(x,10,10,dimnames=list(paste0("t",1:10),NULL))
phyDat(mat,"USER",levels=unique(x))
10 sequences with 10 character and 10 different site patterns.
The states are n t s o y e c h z q m j d o h n z y x p q g u o a i h y c g t d f y t d f e u e f d i j r z x w u m a j p j g d t q y v o x p m s o z x z a y j z r u s a y k l f g l f r i l r f m t t e f x v f g q j


---

