I apologize not providing enough details in my first post...
What I show now is literally all what I use to figure out the mechanics of
working with data.tree
.
I am trying to organize the output of numerical simulations in a tree structure for later use with the data.tree
package in R. The initial (predefined) structure of my tree is (couldn't get the first two lines into the grey box):
require("data.tree")
mcdata <- Node$new("SNS")
FTS <- mcdata$AddChild("First Target Station")
BL1A <- FTS$AddChild("Beamline 1A")
BL1B <- FTS$AddChild("Beamline 1B")
BL1C <- FTS$AddChild("Beamline 1C")
BL2 <- FTS$AddChild("Beamline 2")
BL3 <- FTS$AddChild("Beamline 3")
BL10 <- FTS$AddChild("Beamline 10")
BL11A <- FTS$AddChild("Beamline 11A")
BL11B <- FTS$AddChild("Beamline 11B")
BL12 <- FTS$AddChild("Beamline 12")
STS <- mcdata$AddChild("Second Target Station")
BL1 <- STS$AddChild("Beamline 1")
BL2 <- STS$AddChild("Beamline 2")
BL3 <- STS$AddChild("Beamline 3")
BL4 <- STS$AddChild("Beamline 4")
BL5 <- STS$AddChild("Beamline 5")
Processing simulation output files results in something like
result <- c("First Target Station", "Beamline 11A", "RAPID", ...)
'result' can get much longer but once I have a suitable way to add "RAPID" as a child I figured it should be easy to add whatever children and/or attributes come later. To decide if I need to add a child with name "RAPID" I do the following (knowing that the branches "First Target Station" and "Beamline 11A" exist).
path <- mcdata$"First Target Station"$"Beamline 11A"$"RAPID"
If length(path) is 0 I have to add the child with name "RAPID" otherwise I don't have to do that.
This is straight forward but not really useful for practical purposes. What I think I want is a way to build the 'path' directly with the elements in result. However the naive attempt
path <- mcdata$result[1]$result[2]$result[3]
and several variation to the theme I tried are not working...
Any suggestion how to resolve my little problem will be greatly appreciated...
Thanks,
Chris
P.S. As you can probably tell I am a new 'poster' and not much into the Object Oriented ways of doing things. I apologize in advance if this is not a good way to ask my question.