1.7 Oracle R Enterprise Examples

Oracle R Enterprise includes several example scripts that demonstrate the use of Oracle R Enterprise functions. The following topics describe listing the example scripts and running a script:

1.7.1 Listing the Oracle R Enterprise Examples

You can display a list of the Oracle R Enterprise example scripts with the demo function as shown in the following example.

Example 1-6 Using demo to List Oracle R Enterprise Examples

demo(package = "ORE")
Listing for Example 1-6
R> 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     Hypothesis 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

1.7.2 Running an Oracle R Enterprise Example Script

You can run an Oracle R Enterprise example script with the demo function. Most of the examples use the iris data set that is in the datasets package that is included in the R distribution.

To run an example script, start R, load the ORE packages with library(ORE), connect to the database, and then use the demo function.

Example 1-7 Running the basic.R Example Script

This example runs the basic.R example script. In the listing that follows the example, only the first several lines of the output of the script are shown. The script creates an in-memory database object, IRIS, which is an ore.frame object. The script then demonstrates that the iris data.frame and the IRIS ore.frame have the same structure and contain the same data.

demo("basic", package = "ORE")
Listing for This Example
R> demo("basic", package = "ORE")

        demo(basic)
        ---- ~~~~~
 
Type  <Return>   to start : 
 
R> #
R> #     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
R> #
R> #     Name: basic.R
R> #     Description: Demonstrates basic connectivity to database
R> #
R> #
R> #
R> 
R> ## Set page width
R> options(width = 80)
 
R> # Push the built-in iris data frame to the database
R> IRIS <- ore.push(iris)
 
R> # Display the class of IRIS 
R> class(IRIS)
[1] "ore.frame"
attr(,"package")
[1] "OREbase"
 
R> # Basic commands
R> 
R> # Number of rows
R> nrow(iris)
[1] 150
 
R> nrow(IRIS)
[1] 150
 
R> # Column names of the data frame
R> names(iris)
[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"  "Species"     
 
R> names(IRIS)
[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"  "Species"     

# The rest of the output is not shown.