Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Oracle connect via DBI::dbDriver("Oracle") throws error

I try to do a simple connect to an Oracle database via DBI and ROracle package following instructions from R to Oracle Database Connectivity: Use ROracle for both Performance and Scalability.

When I test the connection via Windows7 > ODBC Data Source Administrator (32bit), the connection is successful. It uses the installed Oracle client OraClient11g_home1 which resides in C:\oracle\Client112_32. ORACLE_HOME environment variable is set to C:\oracle\Client112_32.

I am guessing it may be connected to some 32bit/64bit issue? But even after quite some research I did not find any solution. I also tried running the same in R 32bit but fails as well. BTW, the connection via SQL Developer is also successful.

drv <- DBI::dbDriver("Oracle")
#>Error: Couldn't find driver Oracle. Looked in:
#>* global namespace
#>* in package called Oracle
#>* in package called ROracle
like image 721
Triamus Avatar asked Oct 17 '22 00:10

Triamus


2 Answers

I've had this issue as well. I found that loading the ROracle library beforehand fixes the problem.

library("ROracle")
drv <- DBI::dbDriver("Oracle")

I don't know why though.

like image 122
user11227405 Avatar answered Oct 21 '22 04:10

user11227405


Building on user11227405 answer: it is actually enough to load ROracle without attaching it on the search path; library() does both instead:

loadNamespace("ROracle")
drv <- DBI::dbDriver("Oracle")

that might be preferred e.g. in packages, where changing the search path should be avoided

like image 34
Alberto Dell'Era Avatar answered Oct 21 '22 05:10

Alberto Dell'Era