2011-03-04 6 views
2

R-Excel vba addin을 쓰려고하는데 GetArrayToVBA을 사용하는 데 문제가 있습니다.R-Excel VBA : GetArrayToVBA에 의해 반환 된 값을 추출하는 방법?

예 : 메시지 박스에서

RInterface.StartRServer 
RInterface.RRun "mytst<-4" 
Dim tstVar As Variant, tst As Double 
tstVar = RInterface.GetArrayToVBA("mytst") 
tst = CDbl(testVar) 
MsgBox "count = " & CStr(tst) 
RInterface.StopRServer 

count = 0 결과를 도시. 나는 count = 4을 기대하고 있었다.

답변

2

이것은 VBA 문제입니다. 해당 배열에있는 값을 얻으려면 CDbl() 함께 1x1 배열을 double로 형식 변환 할 수 없습니다. 배열에서 원하는 인덱스 (0,0)를 지정해야합니다. 다음 작품들 :

RInterface.StartRServer 
RInterface.RRun "mytst<-as.matrix(4)" 
Dim tstVar As Variant, tst As Double 
tstVar = RInterface.GetArrayToVBA("mytst") 
tst = CDbl(tstVar(0, 0)) 
MsgBox "count = " & CStr(tst) 
RInterface.StopRServer 
+0

이제는 아름답게 작동합니다. – Steve

관련 문제