I'm attempting to package my software in a way that it will sense whether the pack is present and then install it if not. For example below I take advantage of logical.return within the library function. The reason for this is my code is starting to spread over the world and i would like it to automatically install the necessary packages so that the user does not have to deal with the error when the package is not present.
This set of code is written at the top of all the functions I want to import.
What I envisioned is that this set of code would install the package if it was not present. Yet this set of code does not act as i expected.
My first question is how to specify my CRAN mirror before i execute the code below.
My second question is there a better way to accomplish this?
if( !library(reticulate, logical.return = T) ){
install.packages('reticulate');library(reticulate)
}
if( !library(png, logical.return = T) ){
install.packages('png');library(png)
}
if( !library(RColorBrewer, logical.return = T) ){
install.packages('RColorBrewer');library(RColorBrewer)
}