data.tree icon indicating copy to clipboard operation
data.tree copied to clipboard

Is there a way to FindNode in specific level or add child to a node using variable.?

Open Jeeva-Ganesan opened this issue 7 years ago • 0 comments

Hi.

I am trying to Find a node in a tree with non-unique names.

Lets say, I have this -

data(acme)
acme$Research$AddChild("IT")

When i use FindNode(acme,"IT") It is pointing to different ones in every time. Is there a way I can search only in specific level, may be in level 1 ?

Another thing, I am trying to create the tree programatically like this.

library(data.tree)
construct_tree <- function(x) {

  gq <- Node$new("sessions")
  for(i in 1:nrow(x)) {
    if(x[i,c("type")] != 'RECORD')
       gq$AddChild(x[i,c("name")])
    else{
      y <- as.data.frame(x[i,c('fields')])
      for(j in 1:nrow(y)){
      parent <- x[i,"name"] 
      parent$AddChild(y[j,c("name")])
  }
   }
  }
gq
}

But in this one, i keep getting Error: $ operator is invalid for atomic vectors . Is there a way I can use variable as node names ?

Thanks.

Jeeva-Ganesan avatar Jul 03 '18 11:07 Jeeva-Ganesan