Oracle R Enterpriseの基本的な機能が動作していることを確認するには、Oracle R Enterprise Serverへの接続を確立して、基本的なコマンドをいくつか実行してOracle R Enterpriseのデモ・プログラムの一部を実行します。
注意:
Oracle R Enterpriseを起動および使用するには、ユーザーIDにOracle R Enterpriseのインストールに必要とされる権限が必要です。詳細は、ユーザー要件を参照してください。
例A-2 Oracle R Enterprise Serverへの接続
Oracle R Enterprise ClientをOracle R Enterprise Serverに接続するには、次の手順を実行します。
Windowsの「スタート」メニューでR x64 3.3.0を選択します。
Rコンソールが表示されます。
次のコマンドを入力してOracle R Enterpriseを起動します。
> library(ORE)
次のコマンドを入力してOracle R Enterprise Serverに接続します。次の例では、ユーザーrquser
をサーバー・ホストserv1
上のデータベースorcl
に、ポート1521を使用して接続しています。
> ore.connect(user="rquser", sid="orcl", host="serv1", password="rquserpsw", port=1521, all=TRUE) Loading required package: ROracle Loading required package: DBI
ore.is.connected
を実行して接続を確認します。接続が正常に確立されている場合は、コマンドによってTRUE
が返されます。
> ore.is.connected() [1] TRUE
例A-3 RQUSERからアクセスできるデータベース表のリスト
ore.ls
コマンドで、現行ユーザーに利用可能なデータ・セットがリストされます。たとえば、TABLE1
およびTABLE2
がrquser
スキーマに存在している場合は、次のように表示されます。
> ore.ls() [1] "TABLE1" "TABLE2"
例A-4 Rデータ・フレームのデータ表へのプッシュ
ore.push
コマンドで、Rデータ・フレームがデータ表に、またはデータ表がRデータ・フレームにプッシュされます。次に例を示します。
> cars <- ore.push(cars)
例A-5 埋込みR関数の実行
ore.doEval
コマンドで、データベース埋込みRエンジンの指定された関数の実行がスケジュール設定され、実行結果が返されます。
> ore.doEval(function() { 123 }) [1] 123
例A-6 Oracle R Enterpriseのデモ・スクリプトのリスト
Oracle R Enterpriseのデモ・スクリプトは$ORACLE_HOME/R/library/ORE/demo
にあります。demo
で、利用可能なデモのリストが表示されます。
> 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
Oracle R Enterpriseのデモ・スクリプトの一部を実行することにより、インストールが正常に完了したことをさらに確認できます。エラーが発生せずスクリプトが完了した場合、デモは正常に実行されています。
例A-7 aggregateデモの実行
次の例では、aggregate
デモが出力の一部を含めて表示されています。
> 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" . . . .
例A-8 row_applyデモの実行
次の例では、row_apply
デモが出力の一部を含めて表示されています。
> 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` . . . .
例A-9 corデモの実行
次の例では、cor
デモが出力の一部を含めて表示されています。
> 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
例A-10 stepwiseデモの実行
次の例では、stepwise
デモが出力の一部を含めて表示されています。
> 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 . . .