R: using character vector subset within 'require' function not working -
this question has answer here:
- load r package character string 2 answers
in order function work correctly, first need load packages. want load packages automatically. is, in first part of code, whether required package loaded, load if not loaded. came code below
#install and/or load necessary packages packages <- c("chron","ncdf","rgdal") i.count <- 1 while (i.count <= length(packages)) { if (packages[i.count] %in% rownames(installed.packages()) == false) { install.packages(packages[i.count]) require(packages[i.count]) } else if (packages[i.count] %in% (.packages()) == false) { require(packages[i.count]) } i.count = i.count + 1 } given above code, getting following err when running line require(packages[i.count])
err:
c("loading required package: [", "loading required package: packages", "loading required package: i.count") failed error: ‘'package' must of length 1’ in addition: warning message: in if (!loaded) { : condition has length > 1 , first element used any appreciated.
try:
require(packages[i.count],character.only=true)
Comments
Post a Comment