Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R cannot find specific function in a package

I'm using the randomForest package (v 4.6-7) in R (v 2.15.3) and can easily use the function randomForest to create a model. However, when I try to predict on my test set, the predict.randomForest function cannot be found. I've also tried plotting with plot.randomForest only to get the same error, "could not find function."

I've already tried reinstalling the package (figuring maybe it was out of date) and made sure the spelling is absolutely correct. I cannot figure out what's causing this error, any ideas?

like image 691
paulsef11 Avatar asked Jun 21 '13 00:06

paulsef11


People also ask

What is this %>% in R?

The pipe operator, written as %>% , has been a longstanding feature of the magrittr package for R. It takes the output of one function and passes it into another function as an argument. This allows us to link a sequence of analysis steps.

What package is %>% in in R?

%>% is called the forward pipe operator in R. It provides a mechanism for chaining commands with a new forward-pipe operator, %>%. This operator will forward a value, or the result of an expression, into the next function call/expression. It is defined by the package magrittr (CRAN) and is heavily used by dplyr (CRAN).

Why is object not found in R?

This error usually occurs for one of two reasons: Reason 1: You are attempting to reference an object you have not created. Reason 2: You are running a chunk of code where the object has not been defined in that chunk.


1 Answers

It appears that the functions of interest are not exported from the package.

If you use ls(package:randomForest) you'll get a list of the exported functions.

If you want to see all the functions available the use: ls(getNamespace("randomForest"), all.names=TRUE). Thanks @Joshua. You'll see the functions you want there.

In order to refer to one of them explicitly, use: randomForest:::predict.randomForest() or just make a object which inherits the class 'randomForest' and call predict() on it directly.

like image 124
dardisco Avatar answered Sep 21 '22 12:09

dardisco