Skip to content

Commit bcc9c5f

Browse files
committed
reorder and put more explanation to usage of extract_calls
1 parent 751e6ca commit bcc9c5f

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

R/utils-get_code_dependency.R

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,19 @@ extract_side_effects <- function(pd) {
318318
unlist(strsplit(sub("\\s*#\\s*@linksto\\s+", "", linksto), "\\s+"))
319319
}
320320

321+
#' @param parsed_code results of `parse(text = code, keep.source = TRUE` (parsed text)
322+
#' @keywords internal
323+
#' @noRd
324+
extract_dependency <- function(parsed_code) {
325+
pd <- normalize_pd(utils::getParseData(parsed_code))
326+
reordered_pd <- extract_calls(pd)[[1]]
327+
# extract_calls is needed to reorder the pd so that assignment operator comes before symbol names
328+
# extract_calls is needed also to substitute assignment operators into specific format with fix_arrows
329+
# extract_calls is needed to omit empty calls that contain only one token `"';'"`
330+
# This cleaning is needed as extract_occurrence assumes arrows are fixed, and order is different than in original pd.
331+
c(extract_side_effects(reordered_pd), extract_occurrence(reordered_pd))
332+
}
333+
321334
# graph_parser ----
322335

323336
#' Return the indices of calls needed to reproduce an object
@@ -384,6 +397,10 @@ detect_libraries <- function(graph) {
384397
)
385398
}
386399

400+
401+
# utils -----------------------------------------------------------------------------------------------------------
402+
403+
387404
#' Normalize parsed data removing backticks from symbols
388405
#'
389406
#' @param pd `data.frame` resulting from `utils::getParseData()` call.
@@ -400,6 +417,10 @@ normalize_pd <- function(pd) {
400417
pd
401418
}
402419

420+
421+
# split_code ------------------------------------------------------------------------------------------------------
422+
423+
403424
#' Get line/column in the source where the calls end
404425
#'
405426
#'
@@ -458,11 +479,3 @@ split_code <- function(code) {
458479
gsub("^([[:space:]])*;(.+)$", "\\1\\2", new_code, perl = TRUE)
459480
}
460481

461-
#' @param parsed_code results of `parse(text = code, keep.source = TRUE` (parsed text)
462-
#' @keywords internal
463-
#' @noRd
464-
extract_dependency <- function(parsed_code) {
465-
pd <- normalize_pd(utils::getParseData(parsed_code))
466-
reordered_pd <- extract_calls(pd)[[1]] # because ...
467-
c(extract_side_effects(reordered_pd), extract_occurrence(reordered_pd))
468-
}

0 commit comments

Comments
 (0)