2016-08-19 56 views
1

我想在R中使用.COM對象來建立到OLAP多維數據集的ADODB.Connection。爲此,我使用rscproxy,rcom和statconnDCOM軟件包。R&COM對象:如何連接到Windows上的OLAP多維數據集

不過,我沒有真正成功地找到了RCOM包的任何有用的文檔,因此,我在使用R. .COM對象掙扎大時間

我能夠創建一個.COM對象,但我不知道接下來的步驟。我想要做的:

  1. 設置連接字符串
  2. 打開將R < - >多維數據集連接
  3. 執行MDX查詢

請幫我這:-)

代碼:

# 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

正如我在經過大量試驗和錯誤方法後回答了我的問題,我想與您分享解決方案:最後,我從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) 
相關問題