1 Installing and Configuring the Database for Oracle R Enterprise
1.1 Updating Oracle Enterprise Linux 5.5 to 5.8
[root@VMtest1 yum.repos.d]# lsb_release -a
LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: EnterpriseEnterpriseServer
Description:    Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
Release:        5.5

Codename:       Carthage


## mount the file system using iso p_w_picpath.

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=local
baseurl=file:///mnt/Server
gpgcheck=0                                                                                                                

enable=1


## update OEL 5.5 to 5.8
yum check-update
yum update
[root@VMtest1 yum.repos.d]# lsb_release -a
LSB 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-noarch
Distributor ID: EnterpriseEnterpriseServer
Description:    Enterprise Linux Enterprise Linux Server release 5.8 (Carthage)
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 Linux
Oracle 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 Execution
Oracle 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 R
2.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/lib
total 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 Server
3.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' size 2000m;


下载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 ................... Pass
Checking R libraries ......... Pass
Checking ORACLE_HOME ......... Pass
Checking ORACLE_SID .......... Pass
Checking sqlplus ............. Pass
Checking ORACLE instance ..... Pass
Checking ORE ................. Pass
Current 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           = ofsaaicn
Do 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 = TEMP
Installing libraries ......... Pass
Installing RQSYS data ........ Pass
Installing RQSYS code ........ Pass
Installing ORE packages ...... Pass
Creating ORE script .......... Pass
NOTE: 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]$ ls
DBI  ORE  OREbase  OREdm  OREeda  OREgraphics  OREpredict  OREstats  ORExml  png  ROracle
[oracle@VMtest1 library]$ ls -lrt
total 44
drwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREstats
drwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREbase
drwxr-xr-x 8 oracle oinstall 4096 Jan 13 21:38 OREgraphics
drwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREpredict
drwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 ORExml
drwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREeda
drwxr-xr-x 7 oracle oinstall 4096 Jan 13 21:38 OREdm
drwxr-xr-x 8 oracle oinstall 4096 Jan 13 21:38 ORE
drwxr-xr-x 8 oracle oinstall 4096 Jan 13 21:43 ROracle
drwxr-xr-x 8 oracle oinstall 4096 Jan 13 21:44 DBI
drwxr-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 Client
4.1 Installing Oracle Database Instant Client on Linux or UNIX
4.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 -lrt
total 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.rpm
Preparing...                ########################################### [100%]
  1:oracle-instantclient11.########################################### [100%]
[root@VMtest1 oreclient]# rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
Preparing...                ########################################### [100%]
  1:oracle-instantclient11.########################################### [100%]
[root@VMtest1 client64]# pwd
/usr/lib/oracle/11.2/client64
[root@VMtest1 client64]# ls -lrt
total 8
drwxr-xr-x 2 root root 4096 Jan 13 23:01 bin
drwxr-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 -l
total 182304
lrwxrwxrwx 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.so
lrwxrwxrwx 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_profile
export LD_LIBRARY_PATH=$R_HOME/lib:$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/lib
export 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 -lrt
total 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.zip
Archive:  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 -l
total 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 Enterprise
5.1 Creating a Database User for Oracle R Enterprise
5.1.1 Creating RQUSER
使用ORE Server安装介质中的demo_user.sh脚本来创建RQUSER用户:
[oracle@VMtest1 server]$ cd /home/oreserver/server
[oracle@VMtest1 server]$ ./demo_user.sh
Oracle R Enterprise 1.3.1 Server User Creation.
Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
Checking ORACLE_HOME ......... Pass
Checking ORACLE_SID .......... Pass
Checking sqlplus ............. Pass
Checking ORACLE instance ..... Pass
Checking ORE ................. Pass
Current configuration
 ORACLE_HOME          = /u01/app/oracle/product/11.2.0/dbhome_1
 ORACLE_SID           = ofsaaicn
Do 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             = rquser
Creating ORE user ............ Pass
Done

注: 数据库用户rquser的密码是welcome1。


5.1.2 Granting Privileges to RQUSER
sqlplus "/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 RQUSER
GRANT 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:
% ORE
R> library(ORE)
[oracle@VMtest1 server]$ ORE
R version 2.15.3 (2013-03-01) -- "Security Blanket"
Copyright (C) 2013 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: 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 locale
R 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: OREbase
Attaching package: 鈥極REbase鈥?
The following object(s) are masked from 鈥榩ackage:base鈥?
   cbind, data.frame, eval, interaction, order, paste, pmax, pmin,
   rbind, table
Loading required package: OREstats
Loading required package: MASS
Loading required package: OREgraphics
Loading required package: OREeda
Loading required package: OREdm
Loading required package: lattice
Loading required package: OREpredict

Loading required package: ORExml


//测试client端连远程数据库:For a remote database, specify the Oracle Database service identifier (SID), the host name, and the port for the connection.
R> ore.connect(user="RQUSER", sid="ofsaaicn", host="VMtest1", password="welcome1",port=1521, all=TRUE)
Loading required package: ROracle
Loading 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: ROracle
Loading 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 <- ore.push(cars)
> head(cars)
 speed dist
1     4    2
2     4   10
3     7    4
4     7   22
5     8   16
6     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               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
freqanalysis            Frequency cross tabulations
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_dt                  Oracle Data Mining: decision trees
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_svm                 Oracle Data Mining: support vector machines
push_pull               RDBMS <-> R data transfer
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
sql_like                Mapping of R to SQL commands
stepwise                Stepwise OLS linear regression
summary                 Summary functionality
table_apply             Embedded R processing of entire table
>
>
>
>
>
>
> 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"
> x
             species  x
setosa         setosa 50
versicolor versicolor 50
virginica   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's
setosa         setosa  1.0     1.4   1.50 1.462   1.575  1.9    0
versicolor versicolor  3.0     4.0   4.35 4.260   4.600  5.1    0
virginica   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     x
setosa         setosa 1.462
versicolor versicolor 4.260
virginica   virginica 5.552
> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),
+           FUN = min)
             species   x
setosa         setosa 1.0
versicolor versicolor 3.0
virginica   virginica 4.5
> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),
+           FUN = max)
             species   x
setosa         setosa 1.9
versicolor versicolor 5.1
virginica   virginica 6.9
> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),
+           FUN = sd)
             species         x
setosa         setosa 0.1736640
versicolor versicolor 0.4699110
virginica   virginica 0.5518947
> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),
+           FUN = median)
             species    x
setosa         setosa 1.50
versicolor versicolor 4.35
virginica   virginica 5.55
> aggregate(IRIS_TABLE$Petal.Length, by = list(species = IRIS_TABLE$Species),
+           FUN = IQR)
             species     x
setosa         setosa 0.175
versicolor versicolor 0.600
virginica   virginica 0.775
> # More than one grouping column
> x = aggregate(IRIS_TABLE$Petal.Length,
+               by = list(species = IRIS_TABLE$Species,
+                         width = IRIS_TABLE$Petal.Width),
+               FUN = length)
> x
                 species width  x
setosa|0.1         setosa   0.1  5
setosa|0.2         setosa   0.2 29
setosa|0.3         setosa   0.3  7
setosa|0.4         setosa   0.4  7
setosa|0.5         setosa   0.5  1
setosa|0.6         setosa   0.6  1
versicolor|1   versicolor   1.0  7
versicolor|1.1 versicolor   1.1  3
versicolor|1.2 versicolor   1.2  5
versicolor|1.3 versicolor   1.3 13
versicolor|1.4 versicolor   1.4  7
versicolor|1.5 versicolor   1.5 10
versicolor|1.6 versicolor   1.6  3
versicolor|1.7 versicolor   1.7  1
versicolor|1.8 versicolor   1.8  1
virginica|1.4   virginica   1.4  1
virginica|1.5   virginica   1.5  2
virginica|1.6   virginica   1.6  1
virginica|1.7   virginica   1.7  1
virginica|1.8   virginica   1.8 11
virginica|1.9   virginica   1.9  5
virginica|2     virginica   2.0  6
virginica|2.1   virginica   2.1  6
virginica|2.2   virginica   2.2  3
virginica|2.3   virginica   2.3  8
virginica|2.4   virginica   2.4  3
virginica|2.5   virginica   2.5  3
> # Sort the result by ascending value of count
> ore.sort(data = x, by = "x")
                 species width  x
setosa|0.5         setosa   0.5  1
setosa|0.6         setosa   0.6  1
versicolor|1.7 versicolor   1.7  1
versicolor|1.8 versicolor   1.8  1
virginica|1.4   virginica   1.4  1
virginica|1.6   virginica   1.6  1
virginica|1.7   virginica   1.7  1
virginica|1.5   virginica   1.5  2
versicolor|1.1 versicolor   1.1  3
versicolor|1.6 versicolor   1.6  3
virginica|2.2   virginica   2.2  3
virginica|2.4   virginica   2.4  3
virginica|2.5   virginica   2.5  3
setosa|0.1         setosa   0.1  5
versicolor|1.2 versicolor   1.2  5
virginica|1.9   virginica   1.9  5
virginica|2     virginica   2.0  6
virginica|2.1   virginica   2.1  6
setosa|0.3         setosa   0.3  7
setosa|0.4         setosa   0.4  7
versicolor|1   versicolor   1.0  7
versicolor|1.4 versicolor   1.4  7
virginica|2.3   virginica   2.3  8
versicolor|1.5 versicolor   1.5 10
virginica|1.8   virginica   1.8 11
versicolor|1.3 versicolor   1.3 13
setosa|0.2         setosa   0.2 29
> # by descending value
> ore.sort(data = x, by = "x", reverse = TRUE)
                 species width  x
setosa|0.2         setosa   0.2 29
versicolor|1.3 versicolor   1.3 13
virginica|1.8   virginica   1.8 11
versicolor|1.5 versicolor   1.5 10
virginica|2.3   virginica   2.3  8
setosa|0.3         setosa   0.3  7
setosa|0.4         setosa   0.4  7
versicolor|1   versicolor   1.0  7
versicolor|1.4 versicolor   1.4  7
virginica|2     virginica   2.0  6
virginica|2.1   virginica   2.1  6
setosa|0.1         setosa   0.1  5
versicolor|1.2 versicolor   1.2  5
virginica|1.9   virginica   1.9  5
versicolor|1.1 versicolor   1.1  3
versicolor|1.6 versicolor   1.6  3
virginica|2.2   virginica   2.2  3
virginica|2.4   virginica   2.4  3
virginica|2.5   virginica   2.5  3
virginica|1.5   virginica   1.5  2
setosa|0.5         setosa   0.5  1
setosa|0.6         setosa   0.6  1
versicolor|1.7 versicolor   1.7  1
versicolor|1.8 versicolor   1.8  1
virginica|1.4   virginica   1.4  1
virginica|1.6   virginica   1.6  1
virginica|1.7   virginica   1.7  1
> # Preserve just 1 row for duplicate x's
> ore.sort(data = x, by = "x", unique.keys = TRUE)
                 species width  x
setosa|0.5         setosa   0.5  1
virginica|1.5   virginica   1.5  2
versicolor|1.1 versicolor   1.1  3
setosa|0.1         setosa   0.1  5
virginica|2     virginica   2.0  6
setosa|0.3         setosa   0.3  7
virginica|2.3   virginica   2.3  8
versicolor|1.5 versicolor   1.5 10
virginica|1.8   virginica   1.8 11
versicolor|1.3 versicolor   1.3 13
setosa|0.2         setosa   0.2 29
> ore.sort(data = x, by = "x", unique.keys = TRUE, unique.data = TRUE)
                 species width  x
setosa|0.5         setosa   0.5  1
virginica|1.5   virginica   1.5  2
versicolor|1.1 versicolor   1.1  3
setosa|0.1         setosa   0.1  5
virginica|2     virginica   2.0  6
setosa|0.3         setosa   0.3  7
virginica|2.3   virginica   2.3  8
versicolor|1.5 versicolor   1.5 10
virginica|1.8   virginica   1.8 11
versicolor|1.3 versicolor   1.3 13
setosa|0.2         setosa   0.2 29
>
>
>
>
> 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          5.1         3.5          1.4         0.2  setosa              1.4
$`2`
 Sepal.Length Sepal.Width Petal.Length Petal.Width Species dat$Petal.Length
1          4.9           3          1.4         0.2  setosa              1.4
$`3`
 Sepal.Length Sepal.Width Petal.Length Petal.Width Species dat$Petal.Length
1          4.7         3.2          1.3         0.2  setosa              1.3
$`4`
 Sepal.Length Sepal.Width Petal.Length Petal.Width Species dat$Petal.Length
1          4.6         3.1          1.5         0.2  setosa              1.5
$`5`
 Sepal.Length Sepal.Width Petal.Length Petal.Width Species dat$Petal.Length
1            5         3.6          1.4         0.2  setosa              1.4
《略去若干输出》
>
>
>
>
>
> q()
Save workspace p_w_picpath? [y/n/c]: n
至此,Oracle R Enterprise部署完成!!!!