How can I get the depth of the tree in RPART model?
<p>Suppose I build a toy tree model with RPART, how can I get the depth of the tree? </p>

<pre><code>library(rpart)
library(partykit)
fit=rpart(factor(am)~.,mtcars,control=rpart.control(cp=0,minsplit = 1))
plot(as.party(fit))
</code></pre>

<p>I know how to count the leaves, for binary tree, we can approximate the depth by number of leaves, but it is not directly the depth of the tree.</p>

<pre><code>sum(fit$frame$var=="&lt;leaf&gt;")
</code></pre>