Automatically add package:: to functions

Hello, I have written packages and I start to think they have too much dependencies. There are some packages in description that I cannot remember the usecase.
Would there be a package or an add in that would automatically add package:: (hopefully on subset of packages as I do not want to see a zillion base:: or data.table::slight_smile: so I can track usecases and remove some ?

Here's one really crude approach to get the package associated with each function. Yes, it will return a lot of stats and base records, but at least it is in a form you can filter.

It also won't tell you which version of the function you are using (although perhaps that could be inferred from the order of namespace results from getAnywhere, but at least tells you what the potential sources for the function are. You may be able to play with the output from getAnywhere some more to figure out which is in use.

code <- readLines("some_file_path.R")

# Recreate what I put in my file. This is the result of readLines.
code <- c("filter(this that or the other)", 
          "cut(some vector)", 
          "setNames(add the names in here)", 
          "file_test(x, y, z)", 
          "ifelse(cut(x, y, z), yes, no)")


fns <- str_extract_all(code, "[A-Z,a-z][A-Z,a-z,0-9,.,_]+\\(")
fns <- unlist(fns)
fns <- str_replace(fns, "\\(", "")

process_getAnywhere <- function(ga){
  where <- ga$where[grepl("package", ga$where)]
  where <- sub("package[:]", "", where)
                 ga <- process_getAnywhere(getAnywhere(f))
                 data.frame(fn = rep(f, length(ga)),
                            pkg = ga,
                            stringsAsFactors = FALSE)
1 Like

Thank you very much @nutterb

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.