[R] Help needed - Use of RSrvr in macro mode

From: Constant Depièreux <constant.depiereux_at_aqte.be>
Date: Thu 26 May 2005 - 19:12:02 EST


Dear All,

I am experiencing a problem for which I need some help.

I have created a small file containing a simple function

File name = smalltest.r

Content :

smalltest=function(extvar)
{

itworks=paste('Ca marche',date())

setwd("c:/windows/temp")

write.table(itworks,file="resultat.csv", append=FALSE)

}

This function works when operated from R environment

To get it performed from Excel, I have write a small function as follows :

Excel file : see attachment (one sheet named 'test', one cell A1 containing : smalltest(NA))

Macro :

Sub smalltest()

    Range("A3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Call RInterface.StartRServer
    Call RInterface.RunRFile("h:\R-Sources\smalltest.r")     Windows("smalltest.xls").Activate
    CommandString = Range("test!a1")
    MsgBox (CommandString)
    Call RInterface.RRun("CommandString")     Workbooks.Open Filename:="c:\windows\temp\resultat.csv"     Range(Selection, Selection.End(xlToRight)).Select     Range(Selection, Selection.End(xlDown)).Select     Selection.Copy
    Windows("smalltest.xls").Activate
    Range("A3").Select
    ActiveSheet.Paste

End Sub

Function works (i.e. does complete without error message) when c:\windows\temp\resultat.csv exists (created using above smalltest function in R environment) but hangs when operated from excel (file not found).

My machine is a 4 Gb Memory - PIV 3.2Ghz with disk mirroring running latest update of XP Pro SP2.

Both R and RServer are latest editions available.

Does anybody have an idea of what the problem might be?

Many thanks for your advices.

Best regards.

Constant Depièreux

smalltest=function(extvar)
{

itworks=paste('Ca marche',date())

setwd("c:/windows/temp")

write.table(itworks,file="resultat.csv", append=FALSE)

}



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu May 26 19:37:40 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:07 EST