|
1 Installing and Configuring the Database for Oracle R Enterprise1.1 Updating Oracle Enterprise Linux 5.5 to 5.8[root@VMtest1 yum.repos.d]# lsb_release -aLSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarchDistributor>Description: Enterprise Linux Enterprise Linux Server>Release: 5.5 Codename: Carthage
## mount the file system using iso image. mount OL5.8.iso /mnt/ -o loop
## edit yum repository$> cd /etc/yum.repo.d/$> mkdir repobak $> mv /etc/yum.repo.d/*.repo repobak
## edit local.repo[root@VMtest1 yum.repos.d]# cat local.repo [base]name=localbaseurl=file:///mnt/Servergpgcheck=0 enable=1
## update OEL 5.5 to 5.8yum check-updateyum update[root@VMtest1 yum.repos.d]# lsb_release -aLSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarchDistributor>Description: Enterprise Linux Enterprise Linux Server>Release: 5.8 Codename: Carthage
1.2 Installing Oracle Database for Oracle R Enterprise 安装Oracle 11.2.0.3。
1.3 Patching an 11.2.0.1 or 11.2.0.2 Database on LinuxOracle R Enterprise 1.3.1 requires Oracle Database 11.2.0.3, 11.2.0.4, or 12.1. On Linux, Oracle R Enterprise can also work with an 11.2.0.1 or 11.2.0.2 database if it is properly patched. 注:ORE对数据库版本的最低要求是11.2.0.3。所以如果安装的初始版本是低于11.2.0.3,需要先升级到11.2.0.3。本次测试环境的数据库版本为11.2.0.3,故无需再升级。
1.4 Configuring EXTPROC for Embedded R ExecutionOracle Database uses an external procedure agent named extproc to support external procedures. Oracle R Enterprise uses extproc to support embedded R execution.By default, extproc supports any external procedure call. If you want to only allow external procedure calls for Oracle R Enterprise, you can edit the EXTPROC_DLLS environment variable in ORACLE_HOME/hs/admin/extproc.ora.SET EXTPROC_DLLS=ONLY:$ORACLE_HOME/lib/ore.so 注:保持缺省配置即可。
2 Installing R2.1 Installing Oracle R Distribution on Linux安装官方文档要求,可以用以下两种方式安装ORD。 ■Installing Oracle R Distribution on Oracle Linux Using Yum■Installing Oracle R Distribution on Oracle Linux Using RPMs但是在机器网络通畅的情况下,连不上oracle的public yum服务器。# cd /etc/yum.repos.d# wget http://public-yum.oracle.com/public-yum-el5.repo执行wget命令是报路由错误。用yum安装R应该是最简单的方法,也是官方文档上推荐的做法,但是yum服务器连接一直有问题。在准备采用rpm包的方式安装时, 一直找不到对应的rpm包,如果能提供rpm包的下载连接, 我们可以再尝试用rpm的方式安装。目前没有找到R-2.15.3的rpm包,所以只能下载源包,自己编译。从R的官方网站上下载相应的包R-2.15.3.tar.gz。 http://cran.r-project.org/src/base/R-2/
上传到服务器上,用root用户解压,编译,安装# gunzip R-2.15.3.tar.gz# tar xvf R-2.15.3.tar# cd R-2.15.3# ./configure --enable-R-shlib# make# make check# make install注:在configure时,一定要加上参数--enable-R-shlib,否则无法生成必须的共享库文件libR.so。安装过程中,再也没有出现之前的错误了,R_HOME/lib下已经有了共享库文件libR.so。[oracle@VMtest1 server]$ ls -l /usr/local/lib64/R/libtotal 15020-rwxr-xr-x 1 root root 422994 Jan 13 21:09 libRblas.so-rwxr-xr-x 1 root root 4039892 Jan 13 21:09 libRlapack.so-rwxr-xr-x 1 root root 10884463 Jan 13 21:09 libR.so ORD安装完毕后,开始安装ORE Server
3 Installing Oracle R Enterprise Server3.1 Installing Oracle R Enterprise Server on Linux or UNIX先在数据库中创建RQ所需的表空间RQSYS,注:可以不创建,在安装ORE Server时会缺省使用SYSAUX。$ sqlplus "/as sysdba"
sql> create tablespace rqsys datafile '/u01/app/oracle/oradata/ofsaaicn/rqsys01.dbf'>下载ORE Server http://www.oracle.com/technetwork/database/options/advanced-analytics/r-enterprise/ore-downloads-1502823.html
下载ore-server-linux-x86-64-1.3.1.zip解压$ unzip ore-server-linux-x86-64-1.3.1.zip $ cd server
开始安装ORE Server:[oracle@VMtest1 server]$ ./install.sh Oracle R Enterprise 1.3.1 Server Installation.Copyright (c) 2012, 2013 Oracle and/or its affiliates. All rights reserved.Checking R ................... PassChecking R libraries ......... PassChecking ORACLE_HOME ......... PassChecking ORACLE_SID .......... PassChecking sqlplus ............. PassChecking ORACLE instance ..... PassChecking ORE ................. PassCurrent configuration R_HOME = /usr/local/lib64/R R_LIBS_USER = /u01/app/oracle/product/11.2.0/dbhome_1/R/library ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1 ORACLE_SID = ofsaaicnDo you wish to install ORE? [yes] Choosing RQSYS tablespaces PERMANENT tablespace to use for RQSYS [SYSAUX]: rqsys ERROR: PERMANENT tablespace rqsys not found PERMANENT tablespace to use for RQSYS [SYSAUX]: RQSYS TEMPORARY tablespace to use for RQSYS [TEMP]: Tablespaces summary PERMANENT tablespace = RQSYS TEMPORARY tablespace = TEMPInstalling libraries ......... PassInstalling RQSYS data ........ PassInstalling RQSYS code ........ PassInstalling ORE packages ...... PassCreating ORE script .......... PassNOTE: ORE has been enabled for all database users. Next, install the supporting packages. You may create an ORE user with the demo_user.sh script, which automatically grants the required privileges. A complete list of privileges is available in the script rquser.sql. To use ORE Embedded R Execution functionality, grant the user the RQADMIN role. Please, consult the documentation for more information.Done 注:在输入rqsys表空间时,一定要输入大写的表空间RQSYS,否则系统找不到表空间名称。
#### 安装ORE Server的support packages:下载ORE Server support安装包ore-supporting-platform-arch-1.3.1.zip解压:$ unzip ore-supporting-platform-arch-1.3.1.zip$ cd supporting安装:$ ORE CMD INSTALL ROracle_1.1-9_R_x86_64-unknown-linux-gnu.tar.gz$ ORE CMD INSTALL DBI_0.2-5_R_x86_64-unknown-linux-gnu.tar.gz$ ORE CMD INSTALL png_0.1-4_R_x86_64-unknown-linux-gnu.tar.gz[oracle@VMtest1 supporting]$ ORE CMD INSTALL ROracle_1.1-9_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?u01/app/oracle/product/11.2.0/dbhome_1/R/library鈥? * installing *binary* package 鈥楻Oracle鈥?...* DONE (ROracle)[oracle@VMtest1 supporting]$ [oracle@VMtest1 supporting]$ ORE CMD INSTALL DBI_0.2-5_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?u01/app/oracle/product/11.2.0/dbhome_1/R/library鈥? * installing *binary* package 鈥楧BI鈥?...* DONE (DBI)[oracle@VMtest1 supporting]$ ORE CMD INSTALL png_0.1-4_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?u01/app/oracle/product/11.2.0/dbhome_1/R/library鈥? * installing *binary* package 鈥榩ng鈥?... * DONE (png)
在目录$ORACLE_HOME/R/library中检查R的package文件:[oracle@VMtest1 ~]$ cd $ORACLE_HOME/R/library[oracle@VMtest1 library]$ pwd/u01/app/oracle/product/11.2.0/dbhome_1/R/library[oracle@VMtest1 library]$ lsDBI ORE OREbase OREdm OREeda OREgraphics OREpredict OREstats ORExml png ROracle[oracle@VMtest1 library]$ ls -lrttotal 44drwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREstatsdrwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREbasedrwxr-xr-x 8 oracle oinstall 4096 Jan 13 21:38 OREgraphicsdrwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREpredictdrwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 ORExmldrwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREedadrwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREdmdrwxr-xr-x 8 oracle oinstall 4096 Jan 13 21:38 OREdrwxr-xr-x 8 oracle oinstall 4096 Jan 13 21:43 ROracledrwxr-xr-x 8 oracle oinstall 4096 Jan 13 21:44 DBIdrwxr-xr-x 9 oracle oinstall 4096 Jan 13 21:44 png
3.2 Verifying the Oracle R Enterprise Server Installation
###### Examine the log files to verify the success of the installation process.[oracle@VMtest1 server]$ pwd/home/oreserver/server[oracle@VMtest1 server]$ ls -l *.log-rw-r--r-- 1 oracle oinstall 2168 Jan 13 21:38 rqinst.log-rw-r--r-- 1 oracle oinstall 6920 Jan 13 21:38 rqproc.log 注:查看上述两个日志文件中是否有error信息。
4 Installing Oracle R Enterprise Client4.1 Installing Oracle Database Instant Client on Linux or UNIX4.1.1 Installing Oracle Instant Client on Linux from RPMs http://www.oracle.com/technetwork/database/features/instant-client/
下载the RPM for Instant Client Package - Basic: oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
下载the RPM for Instant Client Package - SDK :##安装 Installing Oracle Instant Client on Linux from RPMs[root@VMtest1 oreclient]# ls -lrttotal 58764-rw-r--r-- 1 root root 59492344 Jan 13 22:57 oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm-rw-r--r-- 1 root root 609139 Jan 13 22:57 oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm[root@VMtest1 oreclient]# rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpmPreparing... ########################################### [100%] 1:oracle-instantclient11.########################################### [100%][root@VMtest1 oreclient]# rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpmPreparing... ########################################### [100%] 1:oracle-instantclient11.########################################### [100%][root@VMtest1 client64]# pwd/usr/lib/oracle/11.2/client64[root@VMtest1 client64]# ls -lrttotal 8drwxr-xr-x 2 root root 4096 Jan 13 23:01 bindrwxr-xr-x 2 root root 4096 Jan 13 23:02 lib[root@VMtest1 lib]# pwd/usr/lib/oracle/11.2/client64/lib[root@VMtest1 lib]# ls -ltotal 182304lrwxrwxrwx 1 root root 17 Jan 13 23:02 libclntsh.so -> libclntsh.so.11.1-rw-r--r-- 1 root root 52761218 Sep 17 2011 libclntsh.so.11.1-rw-r--r-- 1 root root 7955322 Sep 17 2011 libnnz11.solrwxrwxrwx 1 root root 15 Jan 13 23:02 libocci.so -> libocci.so.11.1-rw-r--r-- 1 root root 1971762 Sep 17 2011 libocci.so.11.1-rw-r--r-- 1 root root 118408281 Sep 17 2011 libociei.so-rw-r--r-- 1 root root 164836 Sep 17 2011 libocijdbc11.so-rw-r--r-- 1 root root 2095661 Sep 17 2011 ojdbc5.jar-rw-r--r-- 1 root root 2714016 Sep 17 2011 ojdbc6.jar-rw-r--r-- 1 root root 300666 Sep 17 2011 ottclasses.zip -rw-r--r-- 1 root root 66779 Sep 17 2011 xstreams.jar
## 将Oracle Instant client libraries路径加入到环境变量$LD_LIBRARY_PATH中//编辑oracle用户的环境变量配置文件.bash_profileexport LD_LIBRARY_PATH=$R_HOME/lib:$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/libexport LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib:$LD_LIBRARY_PATH[oracle@VMtest1 ~]$ echo $LD_LIBRARY_PATH /usr/lib/oracle/11.2/client64/lib:/usr/local/lib64/R/lib:/u01/app/oracle/product/11.2.0/dbhome_1/lib:/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib:/lib:/usr/lib
4.2 Installing the Client Packages on Linux or UNIX解压client package zip :# unzip ore-client-linux-x86-64-1.3.1.zip[oracle@VMtest1 client]$ pwd/home/oreclient/client[oracle@VMtest1 client]$ ls -lrttotal 3976-rw-rw-r-- 1 oracle oinstall 17160 Apr 3 2013 ORExml_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz-rw-rw-r-- 1 oracle oinstall 463821 Apr 3 2013 OREstats_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz-rw-rw-r-- 1 oracle oinstall 66804 Apr 3 2013 OREpredict_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz-rw-rw-r-- 1 oracle oinstall 273572 Apr 3 2013 OREgraphics_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz-rw-rw-r-- 1 oracle oinstall 281311 Apr 3 2013 OREeda_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz-rw-rw-r-- 1 oracle oinstall 178267 Apr 3 2013 OREdm_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz-rw-rw-r-- 1 oracle oinstall 893944 Apr 3 2013 OREbase_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz-rw-rw-r-- 1 oracle oinstall 1848252 Apr 3 2013 ORE_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz 安装Client package:
$ R CMD INSTALL ORE_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz$ R CMD INSTALL OREbase_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz$ R CMD INSTALL OREdm_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz$ R CMD INSTALL OREeda_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz$ R CMD INSTALL OREgraphics_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz$ R CMD INSTALL OREpredict_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz$ R CMD INSTALL OREstats_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz$ R CMD INSTALL ORExml_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz[root@VMtest1 client]# R CMD INSTALL ORE_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥極RE鈥?...* DONE (ORE)[root@VMtest1 client]# R CMD INSTALL OREbase_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥極REbase鈥?...* DONE (OREbase)[root@VMtest1 client]# R CMD INSTALL OREdm_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥極REdm鈥?...* DONE (OREdm)[root@VMtest1 client]# R CMD INSTALL OREeda_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥極REeda鈥?...* DONE (OREeda)[root@VMtest1 client]# R CMD INSTALL OREgraphics_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥極REgraphics鈥?...* DONE (OREgraphics)[root@VMtest1 client]# R CMD INSTALL OREpredict_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥極REpredict鈥?...* DONE (OREpredict)[root@VMtest1 client]# R CMD INSTALL OREstats_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥極REstats鈥?...* DONE (OREstats)[root@VMtest1 client]# R CMD INSTALL ORExml_1.3.1_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥極RExml鈥?... * DONE (ORExml)
4.3 Installing the Client Supporting Packages on Linux or UNIX下载Client Supporting Packages on Linux http://www.oracle.com/technetwork/database/options/advanced-analytics/r-enterprise/ore-downloads-1502823.html
下载ore-supporting-linux-x86-64-1.3.1.zip[oracle@VMtest1 oreclient]$ unzip ore-supporting-linux-x86-64-1.3.1.zipArchive: ore-supporting-linux-x86-64-1.3.1.zip inflating: supporting/DBI_0.2-5_R_x86_64-unknown-linux-gnu.tar.gz inflating: supporting/ROracle_1.1-9_R_x86_64-unknown-linux-gnu.tar.gz inflating: supporting/png_0.1-4_R_x86_64-unknown-linux-gnu.tar.gz [oracle@VMtest1 oreclient]$ cd supporting/[oracle@VMtest1 supporting]$ ls -ltotal 1268-rw-rw-r-- 1 oracle oinstall 958912 Apr 3 2013 DBI_0.2-5_R_x86_64-unknown-linux-gnu.tar.gz-rw-rw-r-- 1 oracle oinstall 46160 Apr 3 2013 png_0.1-4_R_x86_64-unknown-linux-gnu.tar.gz-rw-rw-r-- 1 oracle oinstall 275764 Apr 3 2013 ROracle_1.1-9_R_x86_64-unknown-linux-gnu.tar.gz 安装Client Support Package:
$ R CMD INSTALL DBI_0.2-5_R_x86_64-unknown-linux-gnu.tar.gz $ R CMD INSTALL png_0.1-4_R_x86_64-unknown-linux-gnu.tar.gz $ R CMD INSTALL ROracle_1.1-9_R_x86_64-unknown-linux-gnu.tar.gz[root@VMtest1 supporting]# R CMD INSTALL DBI_0.2-5_R_x86_64-unknown-linux-gnu.tar.gz * installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥楧BI鈥?...* DONE (DBI)[root@VMtest1 supporting]# R CMD INSTALL png_0.1-4_R_x86_64-unknown-linux-gnu.tar.gz * installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥榩ng鈥?...* DONE (png)[root@VMtest1 supporting]# R CMD INSTALL ROracle_1.1-9_R_x86_64-unknown-linux-gnu.tar.gz* installing to library 鈥?usr/local/lib64/R/library鈥? * installing *binary* package 鈥楻Oracle鈥?... * DONE (ROracle)
5 Postinstallation Tasks for Oracle R Enterprise5.1 Creating a Database User for Oracle R Enterprise5.1.1 Creating RQUSER使用ORE Server安装介质中的demo_user.sh脚本来创建RQUSER用户:[oracle@VMtest1 server]$ cd /home/oreserver/server[oracle@VMtest1 server]$ ./demo_user.shOracle R Enterprise 1.3.1 Server User Creation.Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.Checking ORACLE_HOME ......... PassChecking ORACLE_SID .......... PassChecking sqlplus ............. PassChecking ORACLE instance ..... PassChecking ORE ................. PassCurrent configuration ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1 ORACLE_SID = ofsaaicnDo you wish to create an ORE user? [yes] Choosing tablespaces PERMANENT tablespace to use [USERS]: RQSYS TEMPORARY tablespace to use [TEMP]: Choosing user ORE user to use [rquser]: Password to use for user rquser: Tablespaces and user summary PERMANENT tablespace = RQSYS TEMPORARY tablespace = TEMP ORE user = rquserCreating ORE user ............ PassDone 注: 数据库用户rquser的密码是welcome1。
5.1.2 Granting Privileges to RQUSERsqlplus "/as sysdba"GRANT CREATE TABLE TO RQUSER;GRANT CREATE PROCEDURE TO RQUSER;GRANT CREATE VIEW TO RQUSER;GRANT CREATE MINING MODEL TO RQUSER;SQL> GRANT CREATE TABLE TO RQUSER;GRANT CREATE PROCEDURE TO RQUSER;GRANT CREATE VIEW TO RQUSER;GRANT CREATE MINING MODEL TO RQUSER;Grant succeeded.SQL> Grant succeeded.SQL> Grant succeeded.SQL> Grant succeeded.
5.1.3 Granting the RQADMIN Role to RQUSERGRANT RQADMIN to RQUSER;SQL> GRANT RQADMIN to RQUSER; Grant succeeded.
5.2 Connecting Oracle R Enterprise Client to Oracle R Enterprise Server##To connect Oracle R Enterprise client to the database, start R using the ORE script:% ORER> library(ORE)[oracle@VMtest1 server]$ ORE R version 2.15.3 (2013-03-01) -- "Security Blanket"Copyright (C) 2013 The R Foundation for Statistical ComputingISBN 3-900051-07-0Platform: x86_64-unknown-linux-gnu (64-bit)R is free software and comes with ABSOLUTELY NO WARRANTY.You are welcome to redistribute it under certain conditions.Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English localeR is a collaborative project with many contributors.Type 'contributors()' for more information and'citation()' on how to cite R or R packages in publications.Type 'demo()' for some demos, 'help()' for on-line help, or'help.start()' for an HTML browser interface to help.Type 'q()' to quit R.> library(ORE)Loading required package: OREbaseAttaching package: 鈥極REbase鈥?The following object(s) are masked from 鈥榩ackage:base鈥? cbind, data.frame, eval, interaction, order, paste, pmax, pmin, rbind, tableLoading required package: OREstatsLoading required package: MASSLoading required package: OREgraphicsLoading required package: OREedaLoading required package: OREdmLoading required package: latticeLoading required package: OREpredict Loading required package: ORExml
//测试client端连远程数据库:For a remote database, specify the Oracle Database service>R> ore.connect(user="RQUSER", sid="ofsaaicn", host="VMtest1", password="welcome1",port=1521, all=TRUE)Loading required package: ROracleLoading required package: DBI //测试client端连本地数据库:For a local database, specify the connection as follows:
R> ore.connect("RQUSER", password="welcome1", conn_string="", all=TRUE)Loading required package: ROracleLoading required package: DBI 注:连库前需要加载ORE,即 R> library(ORE)
5.3 Validating Basic Oracle R Enterprise Functionality> ore.is.connected()[1] TRUE>ore.ls()character(0)> cars head(cars) speed dist1 4 22 4 103 7 44 7 225 8 166 9 10> ore.doEval(function() { 123 }) [1] 123
6.4 Running the Oracle R Enterprise Example Scripts> demo(package="ORE")Demos in package 鈥極RE鈥?aggregate Aggregationanalysis Basic analysis & data processing operationsbasic Basic connectivity to databasebinning Binning logiccolumnfns Column functionscor Correlation matrixcrosstab Frequency cross tabulationsdatastore DataStore operationsdatetime Date/Time operationsderived Handling of derived columnsdistributions Distribution, density, and quantile functionsdo_eval Embedded R processingfreqanalysis Frequency cross tabulationsgraphics Demonstrates visual analysisgroup_apply Embedded R processing by grouphypothesis Hyphothesis testing functionsmatrix Matrix>nulls Handling of NULL in SQL vs. NA in Rodm_ai Oracle Data Mining: attribute importanceodm_dt Oracle Data Mining: decision treesodm_glm Oracle Data Mining: generalized linear modelsodm_kmeans Oracle Data Mining: enhanced k-means clusteringodm_nb Oracle Data Mining: naive Bayes>odm_svm Oracle Data Mining: support vector machinespush_pull RDBMS R data transferrank Attributed-based ranking of observationsreg Ordinary least squares linear regressionrow_apply Embedded R processing by row chunkssampling Random row sampling and partitioning of an ore.framesql_like Mapping of R to SQL commandsstepwise Stepwise OLS linear regressionsummary Summary functionalitytable_apply Embedded R processing of entire table> > > > > > > demo("aggregate", package="ORE") demo(aggregate) ---- ~~~~~~~~~Type 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>> options(width = 80)> # Push the built-in iris data frame to the database> IRIS_TABLE # Display the>>>[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)>>[1] "ore.frame"attr(,"package")[1] "OREbase"> x species xsetosa setosa 50versicolor versicolor 50virginica virginica 50> # Repeat FUN = summary, mean, min, max, sd, median, IQR> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),+ FUN = summary) species Min. 1st Qu. Median Mean 3rd Qu. Max. NA'ssetosa setosa 1.0 1.4 1.50 1.462 1.575 1.9 0versicolor versicolor 3.0 4.0 4.35 4.260 4.600 5.1 0virginica virginica 4.5 5.1 5.55 5.552 5.875 6.9 0> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),+ FUN = mean) species xsetosa setosa 1.462versicolor versicolor 4.260virginica virginica 5.552> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),+ FUN = min) species xsetosa setosa 1.0versicolor versicolor 3.0virginica virginica 4.5> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),+ FUN = max) species xsetosa setosa 1.9versicolor versicolor 5.1virginica virginica 6.9> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),+ FUN = sd) species xsetosa setosa 0.1736640versicolor versicolor 0.4699110virginica virginica 0.5518947> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),+ FUN = median) species xsetosa setosa 1.50versicolor versicolor 4.35virginica virginica 5.55> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),+ FUN = IQR) species xsetosa setosa 0.175versicolor versicolor 0.600virginica virginica 0.775> # More than one grouping column> x = aggregate(IRIS_TABLE$Petal.Length,+ by = list(species = IRIS_TABLE$Species,+ >+ FUN = length)> x species>setosa|0.1 setosa 0.1 5setosa|0.2 setosa 0.2 29setosa|0.3 setosa 0.3 7setosa|0.4 setosa 0.4 7setosa|0.5 setosa 0.5 1setosa|0.6 setosa 0.6 1versicolor|1 versicolor 1.0 7versicolor|1.1 versicolor 1.1 3versicolor|1.2 versicolor 1.2 5versicolor|1.3 versicolor 1.3 13versicolor|1.4 versicolor 1.4 7versicolor|1.5 versicolor 1.5 10versicolor|1.6 versicolor 1.6 3versicolor|1.7 versicolor 1.7 1versicolor|1.8 versicolor 1.8 1virginica|1.4 virginica 1.4 1virginica|1.5 virginica 1.5 2virginica|1.6 virginica 1.6 1virginica|1.7 virginica 1.7 1virginica|1.8 virginica 1.8 11virginica|1.9 virginica 1.9 5virginica|2 virginica 2.0 6virginica|2.1 virginica 2.1 6virginica|2.2 virginica 2.2 3virginica|2.3 virginica 2.3 8virginica|2.4 virginica 2.4 3virginica|2.5 virginica 2.5 3> # Sort the result by ascending value of count> ore.sort(data = x, by = "x") species>setosa|0.5 setosa 0.5 1setosa|0.6 setosa 0.6 1versicolor|1.7 versicolor 1.7 1versicolor|1.8 versicolor 1.8 1virginica|1.4 virginica 1.4 1virginica|1.6 virginica 1.6 1virginica|1.7 virginica 1.7 1virginica|1.5 virginica 1.5 2versicolor|1.1 versicolor 1.1 3versicolor|1.6 versicolor 1.6 3virginica|2.2 virginica 2.2 3virginica|2.4 virginica 2.4 3virginica|2.5 virginica 2.5 3setosa|0.1 setosa 0.1 5versicolor|1.2 versicolor 1.2 5virginica|1.9 virginica 1.9 5virginica|2 virginica 2.0 6virginica|2.1 virginica 2.1 6setosa|0.3 setosa 0.3 7setosa|0.4 setosa 0.4 7versicolor|1 versicolor 1.0 7versicolor|1.4 versicolor 1.4 7virginica|2.3 virginica 2.3 8versicolor|1.5 versicolor 1.5 10virginica|1.8 virginica 1.8 11versicolor|1.3 versicolor 1.3 13setosa|0.2 setosa 0.2 29> # by descending value> ore.sort(data = x, by = "x", reverse = TRUE) species>setosa|0.2 setosa 0.2 29versicolor|1.3 versicolor 1.3 13virginica|1.8 virginica 1.8 11versicolor|1.5 versicolor 1.5 10virginica|2.3 virginica 2.3 8setosa|0.3 setosa 0.3 7setosa|0.4 setosa 0.4 7versicolor|1 versicolor 1.0 7versicolor|1.4 versicolor 1.4 7virginica|2 virginica 2.0 6virginica|2.1 virginica 2.1 6setosa|0.1 setosa 0.1 5versicolor|1.2 versicolor 1.2 5virginica|1.9 virginica 1.9 5versicolor|1.1 versicolor 1.1 3versicolor|1.6 versicolor 1.6 3virginica|2.2 virginica 2.2 3virginica|2.4 virginica 2.4 3virginica|2.5 virginica 2.5 3virginica|1.5 virginica 1.5 2setosa|0.5 setosa 0.5 1setosa|0.6 setosa 0.6 1versicolor|1.7 versicolor 1.7 1versicolor|1.8 versicolor 1.8 1virginica|1.4 virginica 1.4 1virginica|1.6 virginica 1.6 1virginica|1.7 virginica 1.7 1> # Preserve just 1 row for duplicate x's> ore.sort(data = x, by = "x", unique.keys = TRUE) species>setosa|0.5 setosa 0.5 1virginica|1.5 virginica 1.5 2versicolor|1.1 versicolor 1.1 3setosa|0.1 setosa 0.1 5virginica|2 virginica 2.0 6setosa|0.3 setosa 0.3 7virginica|2.3 virginica 2.3 8versicolor|1.5 versicolor 1.5 10virginica|1.8 virginica 1.8 11versicolor|1.3 versicolor 1.3 13setosa|0.2 setosa 0.2 29> ore.sort(data = x, by = "x", unique.keys = TRUE, unique.data = TRUE) species>setosa|0.5 setosa 0.5 1virginica|1.5 virginica 1.5 2versicolor|1.1 versicolor 1.1 3setosa|0.1 setosa 0.1 5virginica|2 virginica 2.0 6setosa|0.3 setosa 0.3 7virginica|2.3 virginica 2.3 8versicolor|1.5 versicolor 1.5 10virginica|1.8 virginica 1.8 11versicolor|1.3 versicolor 1.3 13setosa|0.2 setosa 0.2 29> > > > > demo("row_apply", package="ORE") demo(row_apply) ---- ~~~~~~~~~Type 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>> options(width = 80)> # Push the built-in iris data frame to the database> IRIS_TABLE # Display the>>>[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.Length1 5.1 3.5 1.4 0.2 setosa 1.4$`2` Sepal.Length Sepal.Width Petal.Length Petal.Width Species dat$Petal.Length1 4.9 3 1.4 0.2 setosa 1.4$`3` Sepal.Length Sepal.Width Petal.Length Petal.Width Species dat$Petal.Length1 4.7 3.2 1.3 0.2 setosa 1.3$`4` Sepal.Length Sepal.Width Petal.Length Petal.Width Species dat$Petal.Length1 4.6 3.1 1.5 0.2 setosa 1.5$`5` Sepal.Length Sepal.Width Petal.Length Petal.Width Species dat$Petal.Length1 5 3.6 1.4 0.2 setosa 1.4《略去若干输出》> > > > > > q()Save workspace image? [y/n/c]: n至此,Oracle R Enterprise部署完成!!!!
|
|