Skip to content

Commit 089514c

Browse files
committed
merge
1 parent 760a5ed commit 089514c

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

R/utils-get_code_dependency.R

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ get_code_dependency <- function(code, names, check_names = TRUE) {
3939
code <- sub("^\\{(.*)\\}$", "\\1", tcode)
4040
}
4141

42-
code <- split_code(code, parsed_code)
4342
parsed_code <- parse(text = code, keep.source = TRUE)
43+
code_split <- split_code(code, parsed_code)
44+
4445
pd <- utils::getParseData(parsed_code)
4546
pd <- normalize_pd(pd)
4647
calls_pd <- extract_calls(pd)
47-
comments <- extract_comments(parsed_code)
48+
#comments <- extract_comments(parsed_code)
4849

4950
if (check_names) {
5051
# Detect if names are actually in code.
@@ -66,7 +67,7 @@ get_code_dependency <- function(code, names, check_names = TRUE) {
6667
lib_ind <- detect_libraries(calls_pd)
6768

6869
code_ids <- sort(unique(c(lib_ind, ind)))
69-
code[code_ids]
70+
code_split[code_ids]
7071
#trimws(paste(as.character(code[code_ids]), comments[code_ids]))
7172
}
7273

@@ -455,20 +456,20 @@ normalize_pd <- function(pd) {
455456
pd
456457
}
457458

458-
#' Extract comments from parsed code
459-
#'
460-
#' @param parsed_code `expression`, result of `parse()` function
461-
#'
462-
#' @return `character` vector of length of `parsed_code` with comments included in `parsed_code`
463-
#' @keywords internal
464-
#' @noRd
465-
extract_comments <- function(parsed_code) {
466-
get_comments <- function(call) {
467-
comment <- call[call$token == "COMMENT", "text"]
468-
if (length(comment) == 0) "" else comment
469-
}
470-
calls <- extract_calls(utils::getParseData(parsed_code))
471-
fixed_calls <- fix_shifted_comments(calls, pattern = "#")
472-
473-
unlist(lapply(fixed_calls, get_comments))
474-
}
459+
#' #' Extract comments from parsed code
460+
#' #'
461+
#' #' @param parsed_code `expression`, result of `parse()` function
462+
#' #'
463+
#' #' @return `character` vector of length of `parsed_code` with comments included in `parsed_code`
464+
#' #' @keywords internal
465+
#' #' @noRd
466+
#' extract_comments <- function(parsed_code) {
467+
#' get_comments <- function(call) {
468+
#' comment <- call[call$token == "COMMENT", "text"]
469+
#' if (length(comment) == 0) "" else comment
470+
#' }
471+
#' calls <- extract_calls(utils::getParseData(parsed_code))
472+
#' fixed_calls <- fix_shifted_comments(calls, pattern = "#")
473+
#'
474+
#' unlist(lapply(fixed_calls, get_comments))
475+
#' }

0 commit comments

Comments
 (0)