Note this this function is used internally and was written to merge Rxs trees (hence the name), so it may not fit other use cases: for example, when merging two leaf nodes with the same name and path, if the value attribute is a list, those lists are combined using base::c().

mergeTrees(
  tree1,
  tree2,
  sourceId,
  filename1,
  filename2,
  spaces = 2,
  silent = metabefor::opts$get("silent")
)

Arguments

tree1, tree2

The trees to merge.

sourceId, filename1, filename2

The identifier of the source and the original file names of the extraction scripts.

spaces

The number of spaces to use in messages (if silent = metabefor::opts$get("silent"))

silent

Whether to be silent or chatty.

Value

The merged tree, a (cloned) data.tree Node object.

Examples

### Load an example Rxs project
data('example_rxsProject_1', package="metabefor");

### Look at the names of the original, raw trees:
names(
  example_rxsProject_1$rxsTrees_raw
);
#> [1] "rxs_minimal_example_module1--complete_1.rxs.Rmd"
#> [2] "rxs_minimal_example_module1--complete_2.rxs.Rmd"
#> [3] "rxs_minimal_example_module2--complete_1.rxs.Rmd"
#> [4] "rxs_minimal_example_module2--complete_2.rxs.Rmd"
#> [5] "rxs_minimal_example_module3--complete_1.rxs.Rmd"
#> [6] "rxs_minimal_example_module3--complete_2.rxs.Rmd"

### Look at the tree for the first module
example_rxsProject_1$rxsTrees_raw[[
  'rxs_minimal_example_module1--complete_1.rxs.Rmd'
]];
#> ###  Tree of extracted entities
#> 
#>                 levelName
#> 1 source                 
#> 2  °--general            
#> 3      ¦--publicationYear
#> 4      ¦--sourceAuthors  
#> 5      °--sourceTitle    
#> ###  Table with extracted entities and extracted values
#> 
#>             path          entity                       nodeValue
#> 1 source/general publicationYear                            2022
#> 2 source/general   sourceAuthors                  Tiffany Aching
#> 3 source/general     sourceTitle Ten lifehacks with a frying pan

### Look at the tree for the second module
example_rxsProject_1$rxsTrees_raw[[
  'rxs_minimal_example_module2--complete_1.rxs.Rmd'
]];
#> ###  Tree of extracted entities
#> 
#>                       levelName
#> 1  source                      
#> 2   ¦--general                 
#> 3   ¦   °--modeInfo            
#> 4   °--methods                 
#> 5       ¦--sample              
#> 6       ¦   ¦--sampleSize      
#> 7       ¦   °--samplingStrategy
#> 8       ¦--method              
#> 9       °--variables           
#> 10          ¦--chalk           
#> 11          °--witches         
#> ###  Table with extracted entities and extracted values
#> 
#>                               path             entity
#> 1                   source/general           modeInfo
#> 2            source/methods/sample         sampleSize
#> 3            source/methods/sample   samplingStrategy
#> 4                   source/methods             method
#> 5   source/methods/variables/chalk variableIdentifier
#> 6   source/methods/variables/chalk   measurementLevel
#> 7 source/methods/variables/witches variableIdentifier
#> 8 source/methods/variables/witches   measurementLevel
#>                                      nodeValue
#> 1                            Lots of more info
#> 2                                            1
#> 3 Wandering the hillsides and collecting sheep
#> 4                                  Qualitative
#> 5                                        chalk
#> 6                                   Continuous
#> 7                                      witches
#> 8                                      Nominal

### Merge them
mergedRxsTree <-
  metabefor::mergeTrees(
    tree1 =
      example_rxsProject_1$rxsTrees_raw[[
        'rxs_minimal_example_module1--complete_1.rxs.Rmd'
      ]],
    tree2 = 
      example_rxsProject_1$rxsTrees_raw[[
        'rxs_minimal_example_module2--complete_1.rxs.Rmd'
      ]],
  );

### View merged tree
mergedRxsTree;
#> ###  Tree of extracted entities
#> 
#>                       levelName
#> 1  source                      
#> 2   ¦--general                 
#> 3   ¦   ¦--publicationYear     
#> 4   ¦   ¦--sourceAuthors       
#> 5   ¦   ¦--sourceTitle         
#> 6   ¦   °--modeInfo            
#> 7   °--methods                 
#> 8       ¦--sample              
#> 9       ¦   ¦--sampleSize      
#> 10      ¦   °--samplingStrategy
#> 11      ¦--method              
#> 12      °--variables           
#> 13          ¦--chalk           
#> 14          °--witches         
#> ###  Table with extracted entities and extracted values
#> 
#>                                path             entity
#> 1                    source/general    publicationYear
#> 2                    source/general      sourceAuthors
#> 3                    source/general        sourceTitle
#> 4                    source/general           modeInfo
#> 5             source/methods/sample         sampleSize
#> 6             source/methods/sample   samplingStrategy
#> 7                    source/methods             method
#> 8    source/methods/variables/chalk variableIdentifier
#> 9    source/methods/variables/chalk   measurementLevel
#> 10 source/methods/variables/witches variableIdentifier
#> 11 source/methods/variables/witches   measurementLevel
#>                                       nodeValue
#> 1                                          2022
#> 2                                Tiffany Aching
#> 3               Ten lifehacks with a frying pan
#> 4                             Lots of more info
#> 5                                             1
#> 6  Wandering the hillsides and collecting sheep
#> 7                                   Qualitative
#> 8                                         chalk
#> 9                                    Continuous
#> 10                                      witches
#> 11                                      Nominal