Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How no more install y/n prompts in R for unsupervised experimentation?

Tags:

r

r-caret

I am testing most of the models caret supports on a bunch of PCs. Unfortunately caret "suggested" packages do not include most of the model packages available to caret. Every time a new version of R comes out I have to sit in front of each PC and wait for each prompt to press the 1 button and Enter. Is there an option I could set to tell R or Rstudio to just install anything asked for? A for every a/s/n prompt too.

list.of.packages <- c("caretEnsemble","logicFS"," RWeka","ordinalNet","xgboost","mlr","caret","MLmetrics","bartMachine","spikeslab","party","rqPen","monomvn","foba","logicFS","rPython","qrnn","randomGLM","msaenet","Rborist","relaxo","ordinalNet","rrf","frbs","extraTrees","ipred","elasticnet","bst","brnn","Boruta","arm","elmNN","evtree","extraTrees","deepnet","kknn","KRLS","RSNNS","partDSA","plsRglm","quantregForest","ranger","inTrees")


new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages, dep = TRUE)


install.packages("mlr", dependencies = c("Depends", "Suggests"))
install.packages("caret", dependencies = c("Depends", "Suggests"))

Code I went with:

 list.of.packages <-getModelInfo(allmodel)[[1]]$library;
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])];
if(length(new.packages)) install.packages(new.packages, dep = TRUE)
like image 488
ran8 Avatar asked Jan 24 '26 15:01

ran8


1 Answers

This code:

getPackages <- function(packs){
  packages <- unlist(
    tools::package_dependencies(packs, available.packages(),
                                which=c("Depends", "Imports", "Suggests"), # 
                                recursive=TRUE)
  )
  packages <- union(packs, packages)
  packages
}

packages <- getPackages(c("caret")) # add in other packages you want here
install.packages(packages)

from https://stackoverflow.com/a/15650828/6619250 allows you to install all dependencies (recursively) from "Depends", "Imports", and "Suggests"

However, actually trying out this code results in a list of 959 (!!) packages because of the list of 'Suggests' packages.

Hence, I would advice you to take a look at the list of "Suggests" packages in CRAN and replace caret with your own list, which you will have to do go through yourself to determine which packages you want.

like image 178
hongsy Avatar answered Jan 27 '26 06:01

hongsy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!