Repository navigation
Use selective imports #5970
Description
Activity
Hi @MichaelChirico i want to work on this issue , can i get assigned and what can be a good approach to know specifically which methods/classes we need to import selectively from the default packages (methods/utils/stats)
One way to do this is to grep for each function in a package. You can list all functions from a package with
ls("package:utils"). With this you can create yourself a regex for searching viagrep. Then you can grep in the R directory withgrep -E -r -n searchString .Note that you might have to use the function name without any brackets since we sometimes assign function aliases like in
freadwith./fread.R:103: FUN = if (w==2L) untar else unzipYou might want to use multiple different search string, e.g. for aliases
paste0("(", paste0(" ", ls("package:utils"), " ", collapse="|"), ")")and for function calls something like(download.file\([a-Z]+|capture.output\([a-Z]+)Michael as regex ninja might come up with a more elegant search string though
Reacted by Nitish JhaOne way to do this is to grep for each function in a package. You can list all functions from a package with
ls("package:utils"). With this you can create yourself a regex for searching viagrep. Then you can grep in the R directory withgrep -E -r -n searchString .Note that you might have to use the function name without any brackets since we sometimes assign function aliases like in
freadwith./fread.R:103: FUN = if (w==2L) untar else unzipYou might want to use multiple different search string, e.g. for aliases
paste0("(", paste0(" ", ls("package:utils"), " ", collapse="|"), ")")and for function calls something like(download.file\([a-Z]+|capture.output\([a-Z]+)Thanks will try using this method :)
I would say it's easier to just remove the import(utils) line and run R CMD check. it should fail and the output will tell you which symbols are not defined anymore.
I would say it's easier to just remove the import(utils) line and run R CMD check. it should fail and the output will tell you which symbols are not defined anymore.
thanks :)
data.table/NAMESPACE
Line 133 in 07fd933
In general it's preferable (perhaps just IMO) to import selectively vs. blanket
import(pkg). Blanket imports risk unintended collisions, especially as packages evolve (add+remove functions), though the risk for the case of default packages (methods/utils/stats) is more borderline.