0

I'm trying to use the trainControl function in this code below in R, but it keeps saying "could not find function "trainControl" " even though I've installed caret.

library(dplyr)
library(ggplot2)
library("mgcv")
library(elasticnet)
library("gam")
library("brnn")
library("nnet")
library("glmnet")
library('caret')
library("clusterSim")
library("neuralnet")
library("randomForest")
library("gbm")
library("plyr")
library("rpart")
library("mlbench")
library("MLmetrics")
library("corrplot")
library(readxl)
install.packages("caret", dependencies = c("Depends", "Suggests"))

DatasetWTI<-read_excel(file.choose())
str(DatasetWTI)
corrplot(cor(DatasetWTI[,-c(1,2)]), method="number")
DatasetWTI$Week<-as.Date(DatasetWTI$Week,tryFormats="%d/%m/%Y")

which(is.na(DatasetWTI),arr.in=TRUE)

#LM
TrainAmount<-209
SetTrain<-head(DatasetWTI,TrainAmount)
SetTest<-tail(DatasetWTI,261-TrainAmount)
ctrl<- trainControl(method="cv",number=10)

Can somebody help? I'm a beginner programmer and could use a useful guidance. Thank you very much!

Phil
  • 7,287
  • 3
  • 36
  • 66
  • 1
    Does this answer your question? [Error: could not find function ... in R](https://stackoverflow.com/questions/7027288/error-could-not-find-function-in-r) – Limey May 12 '22 at 07:47
  • 1
    Are there errors printed after running just `library(caret)` ? – danlooo May 12 '22 at 07:47
  • @danlooo nope. It showed up when I ran ctrl<- trainControl(method="cv",number=10). Apparently I couldnt install caret because I couldn't install its dependencies: recipe. Any clue on this problem? – Vabila Magareta May 12 '22 at 15:22

1 Answers1

0

I had the same error today, but I´ve been working in knitr, so after read some forums and pages I clean the cache and the function work with no issues. So tell me if it works for you.