我想在R中使用.COM对象来建立到OLAP多维数据集的ADODB.Connection。为此,我使用了rscproxy,rcom和statconnDCOM包。
但是,我并没有真正成功地为rcom包找到任何有用的文档,因此,我在R中使用.COM对象时遇到了很多困难。
我能够创建.COM对象,但我不知道接下来的步骤。我想做什么:
请帮助我: - )
代码:
# 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
其他信息:
因为用R-3.3.1安装上面提到的软件包花了我一段时间,所以我想快速概述一下我是如何设法的:
.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()
答案 0 :(得分:0)
我经过大量的试错法后回答了我的问题,我想与你分享解决方案:最后,我从rcom包切换到RDCOMClient包,因为我被困在第一个
下载软件包:
下载RDCOMClient_包的链接:(我使用的是R-3.3.1) https://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.3/
解决方案代码:
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)