@@ -315,20 +315,22 @@ extract_occurrence <- function(pd) {
315315# ' @noRd
316316extract_side_effects <- function (pd ) {
317317 linksto <- grep(" @linksto" , pd [pd $ token == " COMMENT" , " text" ], value = TRUE )
318- unlist(strsplit(sub(" \\ s*#\\ s *@linksto\\ s+" , " " , linksto ), " \\ s+" ))
318+ unlist(strsplit(sub(" \\ s*#. *@linksto\\ s+" , " " , linksto ), " \\ s+" ))
319319}
320320
321321# ' @param parsed_code results of `parse(text = code, keep.source = TRUE` (parsed text)
322322# ' @keywords internal
323323# ' @noRd
324324extract_dependency <- function (parsed_code ) {
325325 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 ))
326+ reordered_pd <- extract_calls(pd )
327+ if (length(reordered_pd ) > 0 ) {
328+ # extract_calls is needed to reorder the pd so that assignment operator comes before symbol names
329+ # extract_calls is needed also to substitute assignment operators into specific format with fix_arrows
330+ # extract_calls is needed to omit empty calls that contain only one token `"';'"`
331+ # This cleaning is needed as extract_occurrence assumes arrows are fixed, and order is different than in original pd.
332+ c(extract_side_effects(reordered_pd [[1 ]]), extract_occurrence(reordered_pd [[1 ]]))
333+ }
332334}
333335
334336# graph_parser ----
0 commit comments