Hi @yonicd,
As I'm diving deeper into the package and making pull requests for some features that I feel would be helpful, I'm noticing an issue that seems to happen at random and I think it's due to the way sinew searches the search list and all possible packages to generate the possible packages.
For example, I have an Rmd document that loads a couple of libraries, and uses certain packages via :: throughout. Randomly, sinew will select a package that's not used anywhere else in the Rmd:
√ stats::filter (2)
√ dplyr::arrange (1)
√ utils::head (1)
√ dplyr::select (1)
√ dplyr::rename_at (2)
√ dplyr::vars (1)
√ sos::matches (2) < Here
√ stringr::str_replace (2)
√ stringr::str_detect (1)
I've been using sinew to namespace all of the R documents on my computer, and it does this quite often. There's probably a number of documents and scripts that are no longer going to work and will need debugging as a result.
To remedy this issue, I was thinking that it would make more sense for sinew to search the documents for all of the following ways in which namespaces are loaded:
library
require
attach
loadNamespace
- roxygen2
@importFrom & @import
-
grep can be used to identify lines in the document with these functions, the lines can be parsed to calls (for all but roxygen comments), and namespaces can be extracted by identifying the appropriate arguments. Resulting package names are then matched with those in the user library to eliminate the possibility of extraneous arguments to these functions being extracted.
roxygen comments can simply be parsed with regex.
-
Namespaces are then aggregated from all calls using :: and added to the list of possible packages.
-
If a function is encountered that is not in the namespaces of these packages, then the user library is searched (and asked for verification if ask = TRUE).
Unlike the other simple feature additions that I've submitted as PRs, making this change will require substantial revisions so I wanted to hear your thoughts on such a change.
Looking forward to your response,
Stephen
Hi @yonicd,
As I'm diving deeper into the package and making pull requests for some features that I feel would be helpful, I'm noticing an issue that seems to happen at random and I think it's due to the way
sinewsearches the search list and all possible packages to generate the possible packages.For example, I have an Rmd document that loads a couple of libraries, and uses certain packages via
::throughout. Randomly,sinewwill select a package that's not used anywhere else in the Rmd:I've been using
sinewto namespace all of the R documents on my computer, and it does this quite often. There's probably a number of documents and scripts that are no longer going to work and will need debugging as a result.To remedy this issue, I was thinking that it would make more sense for
sinewto search the documents for all of the following ways in which namespaces are loaded:libraryrequireattachloadNamespace@importFrom&@importgrepcan be used to identify lines in the document with these functions, the lines can be parsed to calls (for all but roxygen comments), and namespaces can be extracted by identifying the appropriate arguments. Resulting package names are then matched with those in the user library to eliminate the possibility of extraneous arguments to these functions being extracted.roxygen comments can simply be parsed with regex.
Namespaces are then aggregated from all calls using
::and added to the list of possible packages.If a function is encountered that is not in the namespaces of these packages, then the user library is searched (and asked for verification if
ask = TRUE).Unlike the other simple feature additions that I've submitted as PRs, making this change will require substantial revisions so I wanted to hear your thoughts on such a change.
Looking forward to your response,
Stephen