rruntime-errorrandom-forestcaret

Cannot Run Random Forest Models -- Cannot Run Train in R


I'm developing a random forest model. The original the model ran without incident, but will not run now. The error I receive is:

Error in train(Class ~ ., data = dataset, method = "rf", metric = "Accuracy",  : 
  unused arguments (data = dataset, method = "rf", metric = "Accuracy", tuneGrid = tunegrid, trControl = control)

I pulled two examples from the internet and received the same error. The code from one of the internet models is below (code originates from https://rpubs.com/phamdinhkhanh/389752). I assume that the error is something on my side since it is consistent across all of the random forest models I attempt to run.

library(randomForest)
library(mlbench)
library(caret)
library(e1071)

# Load Dataset
data(Sonar)

dataset <- Sonar

x <- dataset[,1:60]
y <- dataset[,61]

#10 folds repeat 3 times
control <- trainControl(method='repeatedcv', 
                        number=10, 
                        repeats=3)

#Metric compare model is Accuracy

metric <- "Accuracy"

set.seed(123)

#Number randomely variable selected is mtry
mtry <- sqrt(ncol(x))

tunegrid <- expand.grid(.mtry=mtry)

rf_default <- train(Class ~ ., 
                    data = dataset, 
                    method = 'rf', 
                    metric = 'Accuracy', 
                    tuneGrid = tunegrid, 
                    trControl = control)

print(rf_default)

Again I end up with:

Error in train(Class ~ ., data = dataset, method = "rf", metric = "Accuracy",  : 
  unused arguments (data = dataset, method = "rf", metric = "Accuracy", tuneGrid = tunegrid, trControl = control)

I've tried changing mtry to hard coded references such as "3", changing tune grid from a separate variable directly entering "expand. grid(.mtry=mtry)", and have double checked the data for missing values.

When I run R.Version() it returns:

$platform
[1] "x86_64-w64-mingw32"

$arch
[1] "x86_64"

$os
[1] "mingw32"

$crt
[1] "ucrt"

$system
[1] "x86_64, mingw32"

Solution

  • Turned R-Studio off and back on again. Models rand without error.