I'm debugging some code and I think I might have twice the same function in 2 packages.
I want to output the package name of the function as it would be executed by the R console.
Examples :
function_package_name(print)
# --> basefunction_package_name(select)
# --> dplyrI cannot simply use ?select
because I think it links to the choice of 2 packages: dplyr
and MASS
.
How can I know which select
function I'm using ?
NB : this is NOT a duplicate of list all functions on CRAN, nor of Find the package names from a function name in R, so sos::findFn()
is not an acceptable answer ! I'm not looking for potential other functions named like this one, I'm looking for the package name of the one I'm currently using !
Every time you start a new R session you'll need to load the packages/libraries that contain functions you want to use, using either library() or require() . If you load a package with the same function name as in another package, you can use packageName::functionName() to call the function directly.
We can find the functions inside a package by using lsf. str function but we need to load the package prior to knowing the functions inside.
You can do both by restarting your R session in RStudio with the keyboard shortcut Ctrl+Shift+F10 which will totally clear your global environment of both objects and loaded packages.
Perhaps even most convenient, if you are just after the package name:
environmentName(environment(select))
The advantage is that this produces a string rather than an environment object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With