A.4 Verifying the Oracle R Enterprise Installation

To verify that the basic functionality of Oracle R Enterprise is working, establish a connection to Oracle R Enterprise Server, execute several basic commands, and run some of the Oracle R Enterprise demo programs.

Note:

To start and use Oracle R Enterprise, your user ID must have the privileges required for Oracle R Enterprise installation. See User Requirements for details.

Example A-2 Connecting to Oracle R Enterprise Server

To connect the Oracle R Enterprise Client to Oracle R Enterprise Server:

  1. Select R x64 3.3.0 from the Windows Start menu.

    The R Console is displayed.

  2. Type this command to start Oracle R Enterprise:

    > library(ORE)
    
  3. Type this command to connect to the Oracle R Enterprise server. The following example connects user rquser to the database orcl on the server host serv1 using port 1521:

    >  ore.connect(user="rquser", sid="orcl", host="serv1", password="rquserpsw",
                   port=1521, all=TRUE)
    Loading required package: ROracle
    Loading required package: DBI
    
  4. Execute ore.is.connected to validate the connection. If the connection is successful, the command returns TRUE:

    > ore.is.connected()
    [1] TRUE
    

Example A-3 Listing the Database Tables Accessible to RQUSER

The ore.ls command lists the data sets that are available to the current user. For example, if TABLE1 and TABLE2 exist in the rquser schema:

> ore.ls()
[1] "TABLE1" "TABLE2"

Example A-4 Pushing an R Data Frame to a Database Table

The ore.push command pushes an R data frame to a database table or a database table to an R data frame. For example:

     > cars <- ore.push(cars)

Example A-5 Executing an Embedded R Function

The ore.doEval command schedules execution of the specified function in the database-embedded R engine and returns the results.

> ore.doEval(function() { 123 })
[1] 123

Example A-6 Listing the Oracle R Enterprise Demo Scripts

The Oracle R Enterprise demo scripts are located in $ORACLE_HOME/R/library/ORE/demo. The demo command provides a list of available demos:

> demo(package="ORE")

Demos in package 'ORE':

aggregate                    Aggregation
analysis                     Basic analysis & data processing operations
basic                        Basic connectivity to database
binning                      Binning logic
columnfns                    Column functions
cor                          Correlation matrix
crosstab                     Frequency cross tabulations
datastore                    DataStore operations
datetime                     Date/Time operations
derived                      Handling of derived columns
distributions                Distribution, density, and quantile functions
do_eval                      Embedded R processing
esm                          Exponential smoothing method
freqanalysis                 Frequency cross tabulations
glm                          Generalized Linear Models
graphics                     Demonstrates visual analysis
group_apply                  Embedded R processing by group
hypothesis                   Hyphothesis testing functions
matrix                       Matrix related operations
nulls                        Handling of NULL in SQL vs. NA in R
odm_ai                       Oracle Data Mining: attribute importance
odm_ar                       Oracle Data Mining: association rules
odm_dt                       Oracle Data Mining: decision trees
odm_em                       Oracle Data Mining: expectation maximization (12.2)
odm_esa                      Oracle Data Mining: explicit semantic analysis (12.2)
odm_glm                      Oracle Data Mining: generalized linear models
odm_kmeans                   Oracle Data Mining: enhanced k-means clustering
odm_nb                       Oracle Data Mining: naive Bayes classification
odm_nmf                      Oracle Data Mining: non-negative matrix factorization
odm_oc                       Oracle Data Mining: o-cluster
odm_partition                Oracle Data Mining: partition model (12.2)
odm_ralg                     Oracle Data Mining: extensible R algorithm (12.2)
odm_svd                      Oracle Data Mining: singular value decomposition (12.2
odm_svm                      Oracle Data Mining: support vector machines
ore_dplyr                    Data manipulation similar to dplyr
pca                          Principal Component Analysis
push_pull                    RDBMS <-> R data transfer
randomForest                 Random forest model          
rank                         Attributed-based ranking of observations
reg                          Ordinary least squares linear regression
row_apply                    Embedded R processing by row chunks
sampling                     Random row sampling and partitioning of an ore.frame
script                       Create, list, load, drop, grant, and revoke R scripts
sql_like                     Mapping of R to SQL commands
stepwise                     Stepwise OLS linear regression
summary                      Summary functionality
table_apply                  Embedded R processing of entire table

A.4.1 Executing Oracle R Enterprise Demo Scripts

You can further verify the success of the installation by running some of the Oracle R Enterprise demo scripts. If a script runs to completion without errors, then the demo is successful.

Example A-7 Executing the aggregate Demo

This example shows the aggregate demo with partial output.

> demo("aggregate", package="ORE")
 
        demo(aggregate)
        ---- ~~~~~~~~~
 
Type  <Return>   to start : 
 
> #
> #     O R A C L E  R  E N T E R P R I S E  S A M P L E   L I B R A R Y
> #
> #     Name: aggregate.R
> #     Description: Demonstrates aggregations
> #     See also summary.R
> #
> #
> #
> 
> ## Set page width
> options(width = 80)
 
> # Push the built-in iris data frame to the database
> IRIS_TABLE <- ore.push(iris)
 
> # Display the class of IRIS_TABLE 
> class(IRIS_TABLE)
[1] "ore.frame"
attr(,"package")
[1] "OREbase"
 
> # Select count(Petal.Length) group by species
> x = aggregate(IRIS_TABLE$Petal.Length,
+               by = list(species = IRIS_TABLE$Species),
+               FUN = length)
 
> class(x)
[1] "ore.frame"
attr(,"package")
[1] "OREbase"
.
.
.
. 

Example A-8 Executing the row_apply Demo

This example shows the row_apply demo with partial output.

> demo("row_apply", package="ORE")
 
        demo(row_apply)
        ---- ~~~~~~~~~
 
Type  <Return>   to start : 
 
> #
> #     O R A C L E  R  E N T E R P R I S E  S A M P L E   L I B R A R Y
> #
> #     Name: row_apply.R
> #     Description: Execute R code on each row
> #
> #
> 
> ## Set page width
> options(width = 80)
 
> # Push the built-in iris data frame to the database
> IRIS_TABLE <- ore.push(iris)
 
> # Display the class of IRIS_TABLE 
> class(IRIS_TABLE)
[1] "ore.frame"
attr(,"package")
[1] "OREbase"
 
> # Apply given R function to each row
> ore.rowApply(IRIS_TABLE,
+              function(dat) {
+                  # Any R code goes here. Operates on one row of IRIS_TABLE at
+                  # a time
+                  cbind(dat, dat$Petal.Length)
+              })
$`1`
  Sepal.Length Sepal.Width Petal.Length Petal.Width   Species dat$Petal.Length
1          6.4         2.8          5.6         2.1 virginica              5.6
 
$`2`
  Sepal.Length Sepal.Width Petal.Length Petal.Width   Species dat$Petal.Length
1          7.2           3          5.8         1.6 virginica              5.8
 
$`3`
  Sepal.Length Sepal.Width Petal.Length Petal.Width   Species dat$Petal.Length
1          7.4         2.8          6.1         1.9 virginica              6.1
 
$`4`
  Sepal.Length Sepal.Width Petal.Length Petal.Width   Species dat$Petal.Length
1          7.9         3.8          6.4           2 virginica              6.4
 
$`5`
  Sepal.Length Sepal.Width Petal.Length Petal.Width   Species dat$Petal.Length
1          6.4         2.8          5.6         2.2 virginica              5.6
 
$`6`
.
.
.
.

Example A-9 Executing the cor Demo

This example shows the cor demo with partial output.

> demo ("cor")
 
        demo(cor)
        ---- ~~~
 
Type  <Return>   to start : 
 
> #
> #     O R A C L E  R  E N T E R P R I S E  S A M P L E   L I B R A R Y
> #
> #     Name: cor.R
> #     Description: Correlation matrix
> #
> #
> #
> 
> ## Set page width
> options(width = 80)
 
> # Push the built-in iris data frame to the database
> IRIS_TABLE <- ore.push(iris)
 
> # Display the class of IRIS_TABLE 
> class(IRIS_TABLE)
[1] "ore.frame"
attr(,"package")
[1] "OREbase"
 
> # Remove non numeric columns
> iris_numeric = IRIS_TABLE[, c("Sepal.Length", "Sepal.Width",
+                               "Petal.Length", "Petal.Width")]
 
> # Pearson's correlation matrix
> cor(iris_numeric, use = "all.obs")
             Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length    1.0000000  -0.1175698    0.8717538   0.8179411
Sepal.Width    -0.1175698   1.0000000   -0.4284401  -0.3661259
Petal.Length    0.8717538  -0.4284401    1.0000000   0.9628654
Petal.Width     0.8179411  -0.3661259    0.9628654   1.0000000
.
.
.
.

Warning messages:
1: ORE object has no unique key - using random order 
2: ORE object has no unique key - using random order 
3: ORE object has no unique key - using random order 
4: ORE object has no unique key - using random order 

Example A-10 Executing the stepwise Demo

This example shows the stepwise demo with partial output.

> demo("stepwise")
 
        demo(stepwise)
        ---- ~~~~~~~~
 
Type  <Return>   to start : 
 
> #
> #     O R A C L E  R  E N T E R P R I S E  S A M P L E   L I B R A R Y
> #
> #     Name: stepwise.R
> #     Description: STEPWISE Multivariate Regression
> #
> #
> #
> 
> ## Set page width
> options(width = 80)
 
> # Push the built-in iris data frame to the database
> IRIS_TABLE <- ore.push(iris)
 
> # Display the class of IRIS_TABLE
> class(IRIS_TABLE)
[1] "ore.frame"
attr(,"package")
[1] "OREbase"
 
> # Let us first project out the non numeric columns
> IRIS_TABLE = IRIS_TABLE[, c("Sepal.Length", "Sepal.Width",
+                             "Petal.Length", "Petal.Width")]
 
> # Predict Sepal.Length based on the other 3 numeric columns
> # Do it stepwise
> model = ore.lm(Sepal.Length ~ ., data = IRIS_TABLE)
 
> model
 
Call:
ore.lm(formula = Sepal.Length ~ ., data = IRIS_TABLE)
 
Coefficients:
 (Intercept)   Sepal.Width  Petal.Length   Petal.Width  
      1.8560        0.6508        0.7091       -0.5565 
.
.
.