在 R 中使用 X4R 包连接到 SSAS(本地)数据立方体? [英] Using X4R package in R to connect to an SSAS (local) data cube?

查看:26
本文介绍了在 R 中使用 X4R 包连接到 SSAS(本地)数据立方体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何使用 X4R 包将本地数据多维数据集加载到 R 中.我可以将多维数据集加载到 Excel 中,但无法将其与 R 一起使用.

I am trying to figure out how to use X4R package to load a local data cube into R. I can load the cube into Excel, but am failing to get this to work with R.

我的多维数据集文件名为\scrsvr\Users\\Documents\Projects\Raw data\data.cub".

My cube filename is "\scrsvr\Users\\Documents\Projects\Raw data\data.cub".

我尝试了以下代码:

library(X4R)
handle<-xmlaConnect(url="\\scrsvr\\Users\\<MyName>\\Documents\\Projects\\Raw data\\data.cub")

不会产生错误.但是,尝试使用 xmlaDiscover 会导致以下错误:

which produces no error. However, trying to use xmlaDiscover results in the following error:

first argument is not an open XMLA handle

谁能帮我连接到我的本地多维数据集?我对此完全陌生,所以也许有人有一个我可以遵循的工作示例(带有示例数据立方体文件)?

Can anyone help me to connect to my local cube? I am totally new to this, so perhaps someone has a working example that I could follow (with example data cube file)?

谢谢!

推荐答案

好的,以防万一其他人将来需要这样做,我设法解决了我的问题

Ok, just in case anyone else needs to do this in future, I managed to solve my problem

# use some necessary packages
require(RDCOMClient)
require(data.table)
library(plyr)
library(Hmisc)

#create connection to SSAS datacube
con <- COMCreate("ADODB.Connection")
con[["ConnectionString"]] <- paste(
  "Provider=MSOLAP.5",
  "Data Source=\\\\scrsvr\\Users\\<MyName>\\Documents\\Projects\\Raw data\\data.cub",
    "Persist Security Info=True",
  sep = ";")
con$Open()

# define the MDX query here:
query = "SELECT ..."

rs <- COMCreate("ADODB.RecordSet")

# submit the MDX query to the cube
rs$Open(query, con)

rs$MoveFirst()    # move to the first row of the record set
nc <- rs$Fields()$Count()     # define number of columns

# get the data into a data array:
dd <- vector("list", length=nc)
dd <- rs$GetRows()  # get the raw data from the results

对于连接,我使用了在设置从 MS Excel 到数据立方体的数据连接时配置的提供程序(MSOLAP.5").一切正常,我现在可以直接使用 MDX 查询数据库.

For the connection, I used the Provider ("MSOLAP.5") that was configured when I set up a data connection from MS Excel to the data cube. It all works and I can now query the database using MDX directly.

这篇关于在 R 中使用 X4R 包连接到 SSAS(本地)数据立方体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆