Reputation: 113
Hello i'm trying this for loop in which i enable multiple libraries in r.
lbs<-c("plyr","dplyr","magrittr","readr")
for (i in 1:length(lbs)) {
library(lb[i])
}
but i get this error
Error in library(lb[i]) : 'package' must be of length 1
My questions covers two dillemas.
How do i use strings stored in vectors to use them in another function?
How do i tell rstudio to enable certain libraries by default every time in open r.
Upvotes: 0
Views: 29
Reputation: 173577
In short:
library()
function is weird. Try library(lb[i],character.only = TRUE)
. There is an example illustrating this at the very bottom of ?library
, for what it's worth.?Startup
, in particular about using .Rprofile
files.Upvotes: 2