Lodrik Lodrik - 3 months ago 19
R Question

R & COM-Objects: How to connect to a OLAP cube on Windows

I would like to use a .COM object in R to establish a ADODB.Connection to an OLAP cube. And for that I'm using the rscproxy, rcom and the statconnDCOM packages.

However, I am not really successful in finding any useful documentation for the rcom package, and therefore, I am struggling big times with using .COM objects in R.

I am able to create a .COM object, but I have no idea about the next steps. What I want to do:


  1. set the connection string

  2. open the R <-> cube connection

  3. execute an mdx query



Please help me with this :-)

.

Code:

# I am quite confident that this section is right:
library(rcom)
conn <- comCreateObject("ADODB.Connection")

# From now on it becomes speculative:
comGetObjectInfo(conn)
connStr = 'Provider=MSOLAP;Data Source=...;Initial Catalog=...;'

# First try to set the connection string:
comSetProperty(conn,"ConnectionString",connStr)

# Second try to set the connection string:
conn[["ConnectionString"]] = connStr

# I try to establish the connection:
conn$Open


.

Other information:

Because it took me quite a while to install the packages mentioned-above with R-3.3.1, I want to give a quick overview on how I managed to do it:

.libPaths()

options(install.packages.check.source = "no")
install.packages(c("rscproxy","rcom"),repos="http://www.autstat.com/download",lib=.Library,type="win.binary")
installstatconnDCOM()
library(rcom)
comRegisterRegistry()

sessionInfo()

Answer

As I have answered my questions after a lot of trial and error approaches, I want to share the solution with you: In the end, I switched from the rcom package to the RDCOMClient package, as I was stuck with the first one.

Download the package:

Download link for the RDCOMClient_ package: (I am using R-3.3.1) https://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.3/

Solution Code:

install.packages("local path to: RDCOMClient_0.93-0.2.zip", repos = NULL, type="source")
library(RDCOMClient)
sessionInfo()

conn = COMCreate("ADODB.Connection")
conn[["State"]]

connStr = 'a connection string'
conn[["ConnectionString"]] = connStr 

conn[["CommandTimeout"]] = 180
conn[["ConnectionTimeout"]] = 30

conn[["State"]] 

conn$Open()

conn[["State"]]

query = 'a query'
results = conn$Execute(query)
Comments