R-function is calculated four-times when starting with RExcel

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

R-function is calculated four-times when starting with RExcel

Corinne D
Hi everyone,

I have the following problem:

I'm starting an R-function via VBA from Excel using the following code:
    ...

    RInterface.StartRServer
    RInterface.RRun "source(" & r_source & ")"
    RInterface.GetArray "function1(" & x1 & "," & x2 & "," x3 & "," x4 & ")", Range(myRange)
    RInterface.StopRServer

    ...

where "r_source" contains the path to the R-script where "function1" is defined and the values for "x1", "x2", etc. are defined earlier in the VBA code. "function1" prints a matrix which is then writen into a sheet in my Excel file (in myRange).

When I define "x1", "x2", etc. directely in R and then evaluate "function1(x1, x2, x3, x4)" in R, the results are (as wished) only calculated once. But if I start it from Excel using the VBA code above, the results are calculated 4-times before the matrix is written into Excel. Which of course is not very time efficient...

Does anyone have an idea how to solve this problem? That would be great!

Thanks a lot in advance! Greets,
Corinne