Running R user defined function from VBA

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Running R user defined function from VBA

Megh
Hi,

I was trying to run an user defined R function from VBA. Therefore I wrote following lines of codes within VBA editor :

sub calculation

    dim xx as double : dim yy as double : xx = 34: yy = 45

    Dim s As StatConnector
    Dim path As String
    Dim z As Variant
    Set s = New StatConnector
    s.Init ("R")
    path = "c:/testing.R"
    s.EvaluateNoReturn filePath
    z = s.Evaluate("x<- test(xx, yy);")
    s.Close

    msgbox z

end sub

here "test()" is an userdefined R function which is saved into a R-file : "c:/testing.R", which is as follows :

test = function (xx, yy){
   return(xx + yy)
}

However I am getting compile error saying "user-defined type not defined". I guess this is coming from "StatConnector" only. If anyone point out how to rectify that, I would be grateful.

Thanks,