1.4.1 About the Transparency Layer

The Oracle Machine Learning for R transparency layer is implemented by the OREbase, OREgraphics, OREdplyr and OREstats packages.

These OML4R packages contain overloaded methods of functions in the open source R base, graphics, and stats packages, respectively.

With the methods and functions in these packages, you can create data.frame and other R proxy objects that correspond to tables and views in your Oracle Database instance. When you run an R expression that uses such an object, the method or function transparently generates a SQL query and sends it to the database. The database then runs the query and typically returns the result also as a proxy object to minimize data movement between the data and the client, as some results may be large.

A database table or view is represented by an ore.frame object, which is a subclass of data.frame. Other OML4R classes inherit from corresponding R classes, such as ore.vector inheriting from vector. OML4R maps Oracle Database data types to OML4R classes, such as NUMBER to the complete mapping list.

You can use the transparency layer methods and functions to prepare database-resident data for analysis. You can then use functions in other OML4R packages to build models and use them to score data.

Example 1-2 Finding the Mean of the Petal Lengths by Species in R

This example shows creating a table called IRIS_TABLE from the R data frame iris. Then using the overloaded aggregate function to compute the mean of petal length for each species.

ore.create(iris, table = 'IRIS_TABLE')
aggplen = aggregate(IRIS_TABLE$Petal.Length,
                    by = list(species = IRIS_TABLE$Species),
                    FUN = mean)
aggplen
Listing for This Example
R> ore.create(iris, table = 'IRIS_TABLE')
R> aggplen = aggregate(IRIS_TABLE$Petal.Length,
                       by = list(species = IRIS_TABLE$Species),
                       FUN = mean)
R> aggplen
              species     x
setosa         setosa 1.462
versicolor versicolor 4.260
virginica   virginica 5.552

Example 1-3 SQL Equivalent of the Previous Example

This example shows the SQL equivalent of the aggregate function in the previous example.

SELECT "Species", AVG("Petal.Length")
FROM IRIS_TABLE
GROUP BY "Species"
ORDER BY "Species";
 
Species     AVG("PETAL.LENGTH") 
----------- ------------------- 
setosa       1.4620000000000002 
versicolor   4.26
virginica    5.552