I have seen this error message to mean the CRAN repositories you are using do not have the randomForest package available. Try using a CRAN repository that supplies this package; e.g. options(repos = c(CRAN = "https://cran.rstudio.com")).
Are you able to install randomForest directly first?
Thank you for the suggestion. I did have randomForest installed earlier. Anyways, I think the problem has to do with the version of R and R studio. I removed both from my computer and re-installed the latest versions and the problem was gone.