Reputation: 1488
Can anyone tell me why this code gives the error Error in library(packages[1]) : 'package' must be of length 1
packages <- c("googleVis","dplyr","ggvis","openintro","plotly","maps","RColorBrewer","mapproj","stargazer","swirl")
for (i in 1:length(packages)) {
library(packages[i])
}
I just don't see it. It's a subsetted vector which should be a single character vector for library().
Note: I know that I can use lapply but this is for the sake of the error.
Thanks
Upvotes: 0
Views: 33
Reputation: 1488
Figured it out. Just by adding character.only=T as an argument to the library function.
Upvotes: 2