Lodrik
Lodrik

Reputation: 639

RDCOMClient package: How to read data from a query

I am currently on the issue to connect to a Cube with R using .COM objects, to then gathering data from the Cube via mdx-queries. As in my previous question described (see link below), I can now connect to the cube with the help of the RDCOMClient package and R version 3.3.1, and can also send queries to the cube. Moreover, when tracing my connection with the SQL Server Profiler, I can see it connected correctly + I also see that my query is executed without errors.

However, I have no idea how I can obtain my data inside R. I save the query result in the variable results, but I am unable to do anything with it. Can you help me display my query results in R please?

.

Connection + Query Code:

conn = COMCreate("ADODB.Connection")

connStr = 'my connection string'
conn[["ConnectionString"]] = connStr 

conn$Open()
conn[["State"]]  

query = 'some query. 100% correct, tested with other tools'
results = conn$Execute(query)

.

Information for the results variable: (Code, followed by the Output)

names = slotNames(results)
names 

[1] "ref"

.

slot(results,names[1])

pointer: 0x0000000015d63c60

.

str(results)

Formal class 'COMIDispatch' [package "RDCOMClient"] with 1 slot

..@ ref:

.

class(results)

[1] "COMIDispatch" attr(,"package") [1] "RDCOMClient"

.

attributes(results)

$ref

$class

[1] "COMIDispatch"

attr(,"package")

[1] "RDCOMClient"

.

Thanks for helping :-)

.

Previous question: R & COM-Objects: How to connect to a OLAP cube on Windows

Upvotes: 1

Views: 843

Answers (1)

Parfait
Parfait

Reputation: 107767

Consider using ADO's GetRows() method which returns records of a recordset in a nested VBA array which would translate into a nested R list. Currently, you only retrieve the recordset object.

results = conn$Execute(query)$GetRows()

Upvotes: 1

Related Questions