问题
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:
- set the connection string
- open the R <-> cube connection
- 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()
回答1:
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)
来源:https://stackoverflow.com/questions/39042980/r-com-objects-how-to-connect-to-a-olap-cube-on-windows