R: using character vector subset within 'require' function not working -


this question has answer here:

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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -