Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: awilliams1024Hi Alejandro,
Yes, you can install CRAN library packages using an R script within the Power R node. The procedure is the same as that when installing a package in the R console - i.e. using the R language install.packages() function. For LAE desktop you can install the binary packages directly from CRAN. For Linux you will have to compile the packages from the source versions of the libraries. Here is an example of the Power R node configured to install a package (in this case 'zoom' from the main CRAN site). Copy the node definition below and paste it onto the BRE canvas.
node:Power_R
bretype:lal1::Power R
editor:sortkey=552ce3ee765f2ef9
output:554c6afc73a64d03/out1=
prop:LogLevel=0
prop:RScript=<<EOX
## Setup additional library path
#myLibrary = "c:/Lavastorm/LAETemp/tmp/brain" # LAE 5.x/ 6.0
#myLibrary = "c:/Lavastorm/LAETemp/tmp/admin" # LAE 6.1
myLibrary = "{{%ls.brain.tempDir%}}" # Version/platform independent
.libPaths( c( .libPaths(), myLibrary) )
## Set the working directory
setwd("{{%ls.brain.tempDir%}}")
## Set the script to use the CRAN repository
Repos = getOption("repos")
Repos["CRAN"] = "
http://cran.us.r-project.org"
#Repos["CRAN"] = "
http://lib.stat.cmu.edu/R/CRAN" # Specify a particular mirror
options(repos = Repos)
## Function to check whether package is installed
is.installed <- function(mypkg){
is.element(mypkg, installed.packages()[,1])
}
## Get the platform OS type - It will be "windows" or "unix"
OStype <- .Platform$OS.type
# check if package "zoom" is installed
if (OStype == "windows" & !is.installed("zoom")){
install.packages("zoom", type="win.binary", myLibrary)
}
## Remove the Repos variable
rm(Repos)
########################################
out1 <- data.frame(Installed=is.installed("zoom"))
EOX
editor:XY=360,120
end:Power_R
When run, the node will download and install the package into the specified library location ('C:\Lavastorm\LAETemp\tmp' in this case) and outputs an indication on whether the library is installed after the installation process has completed. The package is only downloaded and installed if it is not already present on the machine. Obviously, internet access is required and the node will only attempt to install the package if it is run on a Windows machine.
For further information on installation of packages see the following sources:
The install.packages() description can be viewed here:
https://cran.r-project.org/doc/manua...lling-packages
The R installation and administration guide provides a lot of detailed information:
https://cran.r-project.org/doc/manua...lling-packages
Re. the R Library Package Download node: it is a utility node that automates the process of downloading and installing the set of libraries that are prerequisites for the operation of the nodes in the Statistical and Predictive Analytics node pack (e.g. the Market Basket Analysis node and Quantile Regression node).
Best regards,
Adrian