问题描述
我想在R中使用.COM对象来建立与OLAP多维数据集的ADODB.Connection。为此,我使用rscproxy,rcom和statconnDCOM包。
但是,我并没有真正成功地找到rcom软件包的任何有用的文档,因此,我在R.使用.COM对象努力的时间很长。 p>
我可以创建一个.COM对象,但我不知道接下来的步骤。我要做什么:
- 设置连接字符串
- 打开R& - 多维数据集连接
- 执行mdx查询
请帮助我: - )
。
代码:
#我相信这一节是正确的:
library rcom)
conn< - comCreateObject(ADODB.Connection)
#从现在开始变成推测:
comGetObjectInfo(conn)
connStr ='Provider = MSOLAP; Data Source = ...;初始目录= ...;'
#首先尝试设置连接字符串:
comSetProperty(conn,ConnectionString,connStr)
#第二次尝试设置连接字符串:
conn [[ConnectionString]]] = connStr
#尝试建立连接:
conn $ Open
。
其他信息:
由于我花了很长时间来安装上面提到的包和R-3.3.1,我想快速概述了我是如何做到的:
.libPaths()
选项(install.packages .check.source =no)
install.packages(c(rscproxy,rcom),repos =http://www.autstat.com/download,lib = .Library,type =win.binary)
installstatconnDCOM()
库(rcom)
comRegisterRegistry()
sessionInfo()
由于我已经在大量试验和错误方法后回答了我的问题,与您:最后,我从rcom包切换到RDCOMClient包,因为我被困在第一个包。
下载包: / strong>
RDCOMClient_软件包的下载链接:(我使用的是R-3.3.1)
解决方案代码:
install.packages(local path to:RDCOMClient_0.93-0.2.zip,repos = NULL,type =source)
库(RDCOMClient)
sessionInfo b
$ b conn = COMCreate(ADODB.Connection)
conn [[State]]
connStr ='a连接字符串'
conn [ [ConnectionString]] = connStr
conn [[CommandTimeout]] = 180
conn [[ConnectionTimeout]] = 30
conn [ [State]]
conn $ Open()
conn [[State]]
query ='a query'
results = conn $ Execute(query)
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()
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)
这篇关于R& COM对象:如何在Windows上连接到OLAP多维数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!