I have written a loop to install packages in R, whilst I am aware there are other methods to bulk install packages, I don't understand why the loop doesn't work: I get the error message: Error: package
must be character vector of length 1. Which I don't understand because package[i] should return a character vector.
packages<-c("dplyr","ggplot")
for (i in seq_along(packages)){
print(packages[i])
if (!require(packages[i])) install.packages(packages[i])
}
Can anyone suggest any modifications to the above code?