The ore.tableApply
function invokes an R script with an ore.frame
as the input data. The ore.tableApply
function passes the ore.frame
to the user-defined input function as the first argument to that function. The ore.tableApply
function returns an ore.frame
object or a serialized R object as an ore.object
object.
The syntax of the ore.tableApply
function is the following:
ore.tableApply(X, FUN, ..., FUN.VALUE = NULL, FUN.NAME = NULL, FUN.OWNER = NULL)
See Also:
"Arguments for Functions that Run Scripts" for descriptions of the arguments to function ore.tableApply
"Installing a Third-Party Package for Use in Embedded R Execution"
Example 6-12 Using the ore.tableApply Function
This example uses the ore.tableApply
function to build a Naive Bayes model on the iris
data set. The naiveBayes
function is in the e1071
package, which must be installed on both the client and database server machine R engines. As the first argument to the ore.tableApply
function, the ore.push(iris)
invocation creates a temporary database table and an ore.frame
that is a proxy for the table. The second argument is the input function, which has as an argument dat
. The ore.tableApply
function passes the ore.frame
table proxy to the input function as the dat
argument. The input function creates a model, which the ore.tableApply
function returns as an ore.object
object.
library(e1071) nbmod <- ore.tableApply( ore.push(iris), function(dat) { library(e1071) dat$Species <- as.factor(dat$Species) naiveBayes(Species ~ ., dat) }) class(nbmod) nbmodListing for Example 6-12
R> nbmod <- ore.tableApply( + ore.push(iris), + function(dat) { + library(e1071) + dat$Species <- as.factor(dat$Species) + naiveBayes(Species ~ ., dat) + }) R> class(nbmod) [1] "ore.object" attr(,"package") [1] "OREembed" R> nbmod Naive Bayes Classifier for Discrete Predictors Call: naiveBayes.default(x = X, y = Y, laplace = laplace) A-priori probabilities: Y setosa versicolor virginica 0.3333333 0.3333333 0.3333333 Conditional probabilities: Sepal.Length Y [,1] [,2] setosa 5.006 0.3524897 versicolor 5.936 0.5161711 virginica 6.588 0.6358796 Sepal.Width Y [,1] [,2] setosa 3.428 0.3790644 versicolor 2.770 0.3137983 virginica 2.974 0.3224966 Petal.Length Y [,1] [,2] setosa 1.462 0.1736640 versicolor 4.260 0.4699110 virginica 5.552 0.5518947 Petal.Width Y [,1] [,2] setosa 0.246 0.1053856 versicolor 1.326 0.1977527 virginica 2.026 0.2746501