Error in installing ggplot2 package, using with Library (Caret)

I tried several ways to upload all relevant packages but still facing the issue with ggplot2. Tried everything, installed all packages...using R Studio 1.1.4 version

library(caret)
Error: package ‘ggplot2’ required by ‘caret’ could not be found

Is upgrade of R Studio the only way out finally? Please advise way forward.

Have you installed ggplot2 by running install.packages("ggplot2")?

You might also just reinstall caret using:

install.packages("caret", dependencies = TRUE)

Yes, I tried both. Still the below functions are not working
Error in createDataPartition(cars$Transport, p = 0.7, list = FALSE) :
could not find function "createDataPartition"

This is a different problem than the one in your original post, and it's not one I'm able to reproduce:

library(caret)
#> Loading required package: lattice
#> Loading required package: ggplot2
set.seed(3456)
trainIndex <- createDataPartition(iris$Species, p = .8, 
                                  list = FALSE, 
                                  times = 1)
head(trainIndex)
#>      Resample1
#> [1,]         1
#> [2,]         2
#> [3,]         3
#> [4,]         5
#> [5,]         6
#> [6,]         7

Created on 2019-08-28 by the reprex package (v0.3.0)

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

Facing the same issue after installing reprex also

library(caret)
Error: package ‘ggplot2’ required by ‘caret’ could not be found

Within caret, using the below function for knn model

random <- createDataPartition(cars$Transport, p=0.70, list=FALSE)

Have you manually installed ggplot2?

install.packages("ggplot2")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.