CRAN

The Comprehensive R Archive Network (CRAN) is a network of servers around the world that storeR distributions, extensions, documentation, and binaries. Most of the mirror servers are hosted on universities across the world, creating an active, open source community. The repository is extensively used by the R community, due to the large number of add-on packages, which are generally available under the GPL license. Users can take advantage of the CRAN repository and download the chosen packages, whereas they should consider that these packages are completely external to Netezza.

CRAN packages can be installed on Netezza. The Netezza R library package provides tools for installing and managing CRAN packages.

nzInstallPackages, nzIsPackageInstalled

To install a package, use nzInstallPackages(). Note that on both, the Host and the SPUs, a two-step installation process is the default. The function output (installation log) for a successful installation of a package is presented in the following example.
nzConnectDSN('NetezzaSQL')
nzInstallPackages("http://cran.r-project.org/src/contrib/bitops_1.0-4.1.tar.gz")
#Host:
#Installing: /nz/export/ae/workspace/nz/r_ae/bitops_1.0-4.1.tar.gz
#* installing to library '/nz/export/ae/languages/r/2.10/host/lib64/R/library'
#* installing *source* package 'bitops' ...
#** libs
#/nz/export/ae/sysroot/host/bin/i686-rhel4-linux-gnu-gcc -std=gnu99
#-I/nz/export/ae/languages/r/2.10/host/lib64/R/include -m32 -fpic -m32 -c
#bit-ops.c -o bit-ops.o
#/nz/export/ae/sysroot/host/bin/i686-rhel4-linux-gnu-gcc -std=gnu99
#-I/nz/export/ae/languages/r/2.10/host/lib64/R/include -m32 -fpic -m32 -c
#cksum.c -o cksum.o
#/nz/export/ae/sysroot/host/bin/i686-rhel4-linux-gnu-gcc -std=gnu99 -shared
#-m32 -L/nz/export/ae/sysroot/host/lib -L/nz/export/ae/sysroot/host/usr/lib
#-L/nz/export/ae/sysroot/host/lib -o bitops.so bit-ops.o cksum.o
#-L/nz/export/ae/languages/r/2.10/host/lib64/R/lib -
lR #** R
#** preparing package for lazy loading
#** help
#*** installing help indices
#** building package indices ...
#* DONE (bitops)
#SPUs:
#Installing: /nz/export/ae/workspace/nz/r_ae/bitops_1.0-4.1.tar.gz
#test: ==: binary operator expected
#test: ==: binary operator expected
#* installing to library /nz/export/ae/languages/r/2.10/spu/lib64/R/library #*
installing *source* package bitops ...
#** libs
#gcc -std=gnu99 -I/nz/export/ae/languages/r/2.10/spu/lib64/R/include -m32
#-fpic -m32 -c bit-ops.c -o bit-ops.o
#gcc -std=gnu99 -I/nz/export/ae/languages/r/2.10/spu/lib64/R/include -m32
#-fpic -m32 -c cksum.c -o cksum.o
#gcc -std=gnu99 -shared -m32 -L/nz/export/ae/sysroot/spu/lib
#-L/nz/export/ae/sysroot/spu/usr/lib -liconv -o bitops.so bit-ops.o cksum.o
#-L/nz/export/ae/languages/r/2.10/spu/lib64/R/lib -
lR #** R
#** preparing package for lazy loading
#** help
#*** installing help indices
#** building package indices ...
#* DONE (bitops)

To verify package installation, use nzIsPackageInstalled().
nzIsPackageInstalled(bitops)
# host spus
# TRUE TRUE
nzIsPackageInstalled(RODBC)
# host spus
# TRUE FALSE

Details

The nzInstallPackages() function sends the specified CRAN package to Netezza and installs this package.
  • If the pkg parameter value starts with http://, it is assumed to be a web address. The package is then downloaded from the specified URL and sent to Netezza.
  • If the pkg parameter value is a local file, it is sent to Netezza.
After the file is sent, it is installed on the Netezza system, which involves compiling the C/Fortran code. After the installation and compilation is completed, the installation log is displayed on the screen.
The nzIsPackageInstalled() function checks whether a package is installed on the Netezza Host and SPUs. If the package is found on the Host or SPUs, a message is displayed on the screen. If the package is found in the specified locations, the return value is TRUE. If the package is not found in the specified locations, the return value is FALSE.
nzInstallPackages(pkg, installOnSpus = TRUE)
nzIsPackageInstalled(package)
Where:
pkg
Specifies the local file path or a web address; web addresses must begin with “http://”.
installOnSpus
Optional. When FALSE, the package is not installed on SPUs.
package
Specifies the name of the package to be checked.
Note: The arguments are used with the nzInstallPackages() and nzIsPackageInstalled() functions.
External packages can be used on the client and on the server. In the following example, the external gam package, which is downloaded from CRAN, is used to build a GAM model on the client. This model then uploaded to the server and applied in-database to the records of an Netezza table. This package is installed and loaded on both, Netezza and on client machines, and is used to build the model model1. The pred function, which uses this package, is applied on the Netezza system to an nz.data.frame.
nzInstallPackages("http://cran.r-project.org/src/contrib/akima_0.5-4.tar.gz")
#(... output log from installation omitted for clarity)
nzInstallPackages("http://cran.r-project.org/src/contrib/gam_1.04.tar.gz")
#(... output log from installation omitted for clarity)
install.packages("gam")
library(gam)
library(nzr)
nzConnect("user","password","tt4-r040","nza")
#
# model is build in R locally on the client
#
model1 = gam(Sepal.Length~Petal.Length+Petal.Width, iris, family=gaussian)
nzIris = nz.data.frame("iris")
pred <- function(x, model1) {
require(gam)
predict(model1, data.frame(Petal.Length=as.numeric(x[[2]]),
Petal.Width=as.numeric(x[[3]])))
}
#
# then the model is applied to all rows in the database
#
nzApply(nzIris, FUN=pred, model1=model1)