Sowmya S. Manian Sowmya S. Manian - 2 months ago 18
R Question

Accessing codes for functions using methods with asterisk in its name in R

I am using

randomForest
package in R. I have installed and loaded. Now I want to see the
randomForest()
Function, it says it uses method called `randomForest. I have implemented the following code:

installed.packages("randomForest")
library(randomForest)
randomForest
# function (x, ...)
# UseMethod("randomForest")
# <environment: namespace:randomForest>

methods(randomForest)
# [1] randomForest.default* randomForest.formula*
# see '?methods' for accessing help and source code

randomForest.default
# Error: object 'randomForest.default' not found


Example for
summary()
function,

summary
# function (object, ...)
# UseMethod("summary")
# <bytecode: 0x00000000173508c0>
# <environment: namespace:base>

methods(summary)
# [1] summary,ANY-method summary,diagonalMatrix-method summary,mle-method
# [4] summary,sparseMatrix-method summary.Anova.mlm* summary.aov
# [7] summary.aovlist* summary.aspell* summary.bag*

summary.bag*
+

summary.bag
# Error: object 'summary.bag' not found


As you can see above, few method names have asterisk in it, and rest of them are without them. SO I am able to access codes for methods without asterisk by just typing its name on console.

How to access codes for functions which uses methods having asterisk
*
in its name, what does it signify.

Any help is highly appreciated.
Thanks.

Answer

Functions that end with an asterisks are not exported in the namespace. They are either S3 methods or functions meant for internal use. You can still call them directly using getAnywhere(randomForest.default) or randomForest:::randomForest.default