LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Power R Node

    Employee
    Posted 12-11-2015 06:55

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dialpemo

    Hi All,

    Is there a way to add additional R libraries to the Power R node?

    I tried to use the node itself and R Library Package Download and I was unsuccessful.


    Kind Regards,

    Alejandro Moncada


  • 2.  RE: Power R Node

    Employee
    Posted 12-11-2015 11:02

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: awilliams1024

    Hi 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


  • 3.  RE: Power R Node

    Employee
    Posted 01-05-2016 07:35

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dialpemo

    Thank you Adrianthat work perfectly