Search code examples
rr-caret

Error Using 'Intro to Caret' Vignette Sample Code in R


From the "Intro to Caret" vignette (pdf) you can download from the caret CRAN page, I am tying to run a simple example with built in data.

I get the following error:

Error in { : 
  task 1 failed - "unused arguments (type = "prob", ncomp = modelFit$tuneValue$ncomp)"
In addition: There were 30 warnings (use warnings() to see them)

And all the warnings() seem to follow this pattern:

30: In eval(expr, envir, enclos) :
  predictions failed for Fold10.Rep3: ncomp=15 Error in predict(modelFit, newdata, type = "class") : 
  unused argument (type = "class")

I have other caret examples working, this seems to come up with logistic regression problems that are trying to predict a factor. You should be able to reproduce with:

library(mlbench)
library(caret)

data(Sonar)
set.seed(1)

inTrain <- createDataPartition(y = Sonar$Class, p = 0.75, list = FALSE)

training <- Sonar[inTrain,]
testing <- Sonar[-inTrain,]

ctrl <- trainControl(method = "repeatedcv",
                     repeats = 3,
                     classProbs = TRUE,
                     summaryFunction = twoClassSummary)

model <- train(Class ~ .,
               data = training,
               method = "pls",
               tuneLength = 15,
               trControl = ctrl,
               metric = "ROC",
               preProc = c('center', 'scale'))

I am using R Version 3.3

Any ideas interpreting this error message? Any other posts seem to point to format of the data.frame, but this is built in data and a documented example.


Solution

  • Based on feedback in comments that it was working on other platforms, I chose to wipe out R and reinstall and reinstall all packages, and this resolved. I do occasionally see it come up and it seems to help to clear the workspace.