@@ -364,6 +364,7 @@ extract_dependency <- function(parsed_code) {
364364# ' @keywords internal
365365# ' @noRd
366366graph_parser <- function (x , graph ) {
367+ # x occurrences (lhs)
367368 occurrence <- vapply(
368369 graph , function (call ) {
369370 ind <- match(" <-" , call , nomatch = length(call ) + 1L )
@@ -372,20 +373,21 @@ graph_parser <- function(x, graph) {
372373 logical (1 )
373374 )
374375
376+ # x-dependent objects (rhs)
375377 dependencies <- lapply(graph [occurrence ], function (call ) {
376378 ind <- match(" <-" , call , nomatch = 0L )
377379 call [(ind + 1L ): length(call )]
378380 })
379381 dependencies <- setdiff(unlist(dependencies ), x )
380382
381- if (length( dependencies ) && any( occurrence ) ) {
382- dependency_ids <- lapply( dependencies , function ( dependency ) {
383- graph_parser( dependency , graph [ 1 : max(which(occurrence ))] )
384- } )
385- sort(unique(c(which( occurrence ), unlist( dependency_ids ))) )
386- } else {
387- which( occurrence )
388- }
383+ dependency_occurrences <- lapply( dependencies , function ( dependency ) {
384+ # track down dependencies and where they occur on the lhs in previous calls
385+ last_x_occurrence <- max(which(occurrence ))
386+ reduced_graph <- head( graph [seq_len( last_x_occurrence )], - 1 )
387+ c(graph_parser( dependency , reduced_graph ), last_x_occurrence )
388+ })
389+
390+ sort(unique(c(which( occurrence ), unlist( dependency_occurrences ))))
389391}
390392
391393
0 commit comments