@@ -926,18 +926,29 @@ create_object_identification_id = function(prefix, str){
926
926
# '
927
927
# '@param data data
928
928
# '@param parent parent
929
+ # '@param parent_key column that identifies the parent
930
+ # '@param child_key column that identifies the child
931
+ # '@param recursive if the function is called recursively. Default is \code{TRUE}
932
+ # 'to build the full hierarchy. Can be set to \code{FALSE} to allow lazy loading
933
+ # 'in a Shiny context.
929
934
# '@return a hierarchical list
930
935
# '@export
931
- build_hierarchical_list <- function (data , parent , parent_key , child_key ) {
936
+ build_hierarchical_list <- function (data , parent , parent_key , child_key , recursive = TRUE ) {
932
937
children <- data [data [,parent_key ] == parent , ]
933
938
children <- children [order(children [,child_key ]),]
939
+ out <- list (text = parent )
934
940
if (nrow(children ) == 0 ) {
935
- return (NULL )
941
+ return (out )
936
942
} else {
937
- nested_list <- lapply(1 : nrow(children ), function (i ) {
938
- build_hierarchical_list(data , children [i , child_key ], parent_key , child_key )
943
+ out $ children <- lapply(1 : nrow(children ), function (i ) {
944
+ if (recursive ){
945
+ build_hierarchical_list(data , children [i , child_key ], parent_key , child_key , recursive )
946
+ }else {
947
+ list (
948
+ text = children [i , child_key ]
949
+ )
950
+ }
939
951
})
940
- names(nested_list ) <- children [,child_key ]
941
- return (nested_list )
942
952
}
953
+ return (out )
943
954
}
0 commit comments