@@ -348,35 +348,30 @@ extract_dependency <- function(parsed_code) {
348348 return (character (0L ))
349349 }
350350
351- # Check for expressions
351+ # Check for expressions and process those separetly
352352 expr_ix <- lapply(parsed_code [[1 ]], class ) == " {"
353353
354+ # Build queue of expressions to parse individually
354355 queue <- list ()
355356 parsed_code_list <- if (all(! expr_ix )) {
356357 list (parsed_code )
357358 } else {
358- queue <- as.list(parsed_code [[1 ]])
359- queue [! expr_ix ] <- NULL
360- as.list(parsed_code [[1 ]][! expr_ix ])
359+ queue <- as.list(parsed_code [[1 ]][expr_ix ])
360+ new_list <- parsed_code [[1 ]]
361+ new_list [expr_ix ] <- NULL
362+ list (parse(text = as.expression(new_list ), keep.source = TRUE ))
361363 }
362364
363-
364365 while (length(queue ) > 0 ) {
365366 current <- queue [[1 ]]
366367 queue <- queue [- 1 ]
367368 if (identical(current [[1L ]], as.name(" {" ))) {
368- queue <- append(
369- queue ,
370- lapply(as.list(current )[- 1L ], function (x ) {
371- parse(text = as.expression(x ), keep.source = TRUE )
372- })
373- )
369+ queue <- append(queue , as.list(current )[- 1L ])
374370 } else {
375- parsed_code_list <- c( parsed_code_list , current )
371+ parsed_code_list [[length( parsed_code_list ) + 1 ]] <- parse( text = as.expression( current ), keep.source = TRUE )
376372 }
377373 }
378374
379-
380375 parsed_occurences <- lapply(
381376 parsed_code_list ,
382377 function (parsed_code ) {
@@ -392,6 +387,7 @@ extract_dependency <- function(parsed_code) {
392387 }
393388 )
394389
390+ # Merge results together
395391 result <- Reduce(
396392 function (u , v ) {
397393 ix <- if (" <-" %in% v ) min(which(v == " <-" )) else 0
@@ -406,48 +402,9 @@ extract_dependency <- function(parsed_code) {
406402 x = parsed_occurences
407403 )
408404
409- # browser()
410405 c(extract_side_effects(reordered_full_pd [[1 ]]), result $ left_side , " <-" , result $ right_side )
411406}
412407
413- # ' @keywords internal
414- # ' @noRd
415- extract_assign <- function (pd , assign_call ) {
416- # return(extract_assign(pd, assign_call))
417- # Check if parameters were named.
418- # "','" is for unnamed parameters, where "SYMBOL_SUB" is for named.
419- # "EQ_SUB" is for `=` appearing after the name of the named parameter.
420- if (any(pd $ token == " SYMBOL_SUB" )) {
421- params <- pd [pd $ token %in% c(" SYMBOL_SUB" , " ','" , " EQ_SUB" ), " text" ]
422- # Remove sequence of "=", ",".
423- if (length(params > 1 )) {
424- remove <- integer(0 )
425- for (i in 2 : length(params )) {
426- if (params [i - 1 ] == " =" && params [i ] == " ," ) {
427- remove <- c(remove , i - 1 , i )
428- }
429- }
430- if (length(remove )) params <- params [- remove ]
431- }
432- pos <- match(" x" , setdiff(params , " ," ), nomatch = match(" ," , params , nomatch = 0 ))
433- if (! pos ) {
434- return (character (0L ))
435- }
436- # pos is indicator of the place of 'x'
437- # 1. All parameters are named, but none is 'x' - return(character(0L))
438- # 2. Some parameters are named, 'x' is in named parameters: match("x", setdiff(params, ","))
439- # - check "x" in params being just a vector of named parameters.
440- # 3. Some parameters are named, 'x' is not in named parameters
441- # - check first appearance of "," (unnamed parameter) in vector parameters.
442- } else {
443- # Object is the first entry after 'assign'.
444- pos <- 1
445- }
446- sym <- pd [assign_call + pos , " text" ]
447-
448- gsub(" ^['\" ]|['\" ]$" , " " , sym )
449- }
450-
451408# graph_parser ----
452409
453410# ' Return the indices of calls needed to reproduce an object
0 commit comments