@@ -39,12 +39,12 @@ get_code_dependency <- function(code, names, check_names = TRUE) {
3939 code <- sub(" ^\\ {(.*)\\ }$" , " \\ 1" , tcode )
4040 }
4141
42-
43- code <- parse(text = code , keep.source = TRUE )
44- pd <- utils :: getParseData(code )
42+ code <- split_code( code , parsed_code )
43+ parsed_code <- parse(text = code , keep.source = TRUE )
44+ pd <- utils :: getParseData(parsed_code )
4545 pd <- normalize_pd(pd )
4646 calls_pd <- extract_calls(pd )
47- comments <- extract_comments(code )
47+ comments <- extract_comments(parsed_code )
4848
4949 if (check_names ) {
5050 # Detect if names are actually in code.
@@ -66,7 +66,8 @@ get_code_dependency <- function(code, names, check_names = TRUE) {
6666 lib_ind <- detect_libraries(calls_pd )
6767
6868 code_ids <- sort(unique(c(lib_ind , ind )))
69- trimws(paste(as.character(code [code_ids ]), comments [code_ids ]))
69+ code [code_ids ]
70+ # trimws(paste(as.character(code[code_ids]), comments[code_ids]))
7071}
7172
7273# ' Locate function call token
@@ -141,12 +142,12 @@ get_children <- function(pd, parent) {
141142# ' Fixes edge case of comments being shifted to the next call.
142143# ' @keywords internal
143144# ' @noRd
144- fix_shifted_comments <- function (calls , pattern = " @linksto " ) {
145+ fix_shifted_comments <- function (calls ) {
145146 # If the first or the second token is a @linksto COMMENT,
146147 # then it belongs to the previous call.
147148 if (length(calls ) > = 2 ) {
148149 for (i in 2 : length(calls )) {
149- comment_idx <- grep(pattern , calls [[i ]][, " text" ])
150+ comment_idx <- grep(" @linksto " , calls [[i ]][, " text" ])
150151 if (isTRUE(comment_idx [1 ] < = 2 )) {
151152 calls [[i - 1 ]] <- rbind(
152153 calls [[i - 1 ]],
@@ -156,20 +157,7 @@ fix_shifted_comments <- function(calls, pattern = "@linksto") {
156157 }
157158 }
158159 }
159- calls <- Filter(nrow , calls )
160- # If, after shifting, there are two COMMENTs in one call, paste them.
161- merge_comments <- function (call ) {
162- if (sum(call $ token == " COMMENT" ) > = 2 ) {
163- comments <- call [call $ token == " COMMENT" , " text" ]
164- first_comment_row <- call [which(call $ token == " COMMENT" )[1 ], ]
165- call <- call [call $ token != " COMMENT" , ]
166- first_comment_row $ text <- paste(comments , collapse = " " )
167- rbind(call , first_comment_row )
168- } else {
169- call
170- }
171- }
172- lapply(calls , merge_comments )
160+ Filter(nrow , calls )
173161}
174162
175163# ' Fixes edge case of `<-` assignment operator being called as function,
0 commit comments