attachment icon indicating copy to clipboard operation
attachment copied to clipboard

att_from_* functions shouldn't identify packages within quotes and comments

Open AlexisBrgn opened this issue 1 year ago • 0 comments

When using any att_from_* function on a script containing double colons, it identifies packages that aren't packages. This subsequently breaks any combination with att_to_desc_from_is or similar utility function.

Examples with an xpath using xml2 library :

xml_find_all(ttt, "//tr/th[@id='r6']/following-sibling::td") #att_from_rmd will return `sibling` as a package...

Example with a comment :

filter(df, value > 5) #this is not base::Filter ! <- will return base as a package

I believe the cause of this unwanted behaviour is the regex in att_from_rscripts.R : str_extract_all("[[:alnum:]\\.]+(?=::)") %>%

The regex doesn't seem check the context around supposed "package" as you can see this playground It should be possible to either build a cryptic regex checking if you are within parentheses or comment, or remove comments and quotes with gsub beforehand. In either cases this might lose support for libraries called within string interpolation such as glue("Value : {data.table::fifelse(myvar, 1,2)}

AlexisBrgn avatar Dec 12 '24 14:12 AlexisBrgn