I came across an interesting error when checking the package vector, whether they need to be installed. Requiring and offloading the lme4 namespace gives an error the second time it is executed, but only when some other packages are checked in a specific order.
isInstalled <- function(package) # is a package installed and usable? { loaded <- package %in% .packages() out <- requireNamespace(package, quietly=F) if(!loaded) try(unloadNamespace(package), silent=F) out } isInstalled("car") # All return TRUE isInstalled("nnet") isInstalled("pbkrtest") isInstalled("lme4") isInstalled("nloptr") isInstalled("lme4") # FALSE (only after commands above) # no such symbol NLoptR_Optimize in package C:/__Rlibrary/nloptr/libs/x64/nloptr.dll library(nloptr) # now fails, too # Problem solved if nnet is checked before car (but not again after car)
Am I doing something wrong in isInstalled ?
This may be due to the structure of the car dependencies. Simplified version: 
#install.packages(c("miniCRAN","igraph")) d <- miniCRAN::makeDepGraph(c("car", "nnet", "pbkrtest", "lme4","nloptr"), suggests=FALSE) plot(d)
source share