@@ -918,37 +918,42 @@ create_object_identification_id = function(prefix, str){
918
918
paste(prefix , digest :: digest(object = str , algo = " crc32" , serialize = FALSE ), sep = " _" )
919
919
}
920
920
921
+
922
+ # '@description precompute_relationships
923
+ # '@aliases precompute_relationships
924
+ # '@title precompute_relationships
925
+ # '
926
+ # '@usage precompute_relationships(data, parent_key, child_key)
927
+ # '
928
+ # '@param data data
929
+ # '@param parent_key parent_key
930
+ # '@param child_key child_key
931
+ # '@return a list of relationships
932
+ # '@export
933
+ precompute_relationships <- function (data , parent_key , child_key ) {
934
+ ordered_data <- data [order(data [[parent_key ]], data [[child_key ]]), ]
935
+ relationships <- split(ordered_data [[child_key ]], ordered_data [[parent_key ]])
936
+ return (relationships )
937
+ }
938
+
939
+
921
940
# '@name build_hierarchical_list
922
941
# '@aliases build_hierarchical_list
923
942
# '@title build_hierarchical_list
924
943
# '
925
944
# '@usage build_hierarchical_list(data, parent)
926
945
# '
927
- # '@param data data
928
946
# '@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.
947
+ # '@param relationships relationships
934
948
# '@return a hierarchical list
935
949
# '@export
936
- build_hierarchical_list <- function (data , parent , parent_key , child_key , recursive = TRUE ) {
937
- children <- data [data [,parent_key ] == parent , ]
938
- children <- children [order(children [,child_key ]),]
950
+ build_hierarchical_list <- function (parent , relationships ) {
951
+ children <- relationships [[parent ]]
939
952
out <- list (text = parent )
940
- if (nrow (children ) == 0 ) {
941
- return ( out )
953
+ if (is.null (children )) {
954
+ out $ icon = " fa-regular fa-note-sticky "
942
955
} else {
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
- }
951
- })
956
+ out $ children <- lapply(children , build_hierarchical_list , relationships )
952
957
}
953
958
return (out )
954
959
}
0 commit comments