The problem with file names is that directory separators are
different in R and and in VBA.
So if you are running VBA stuff, you have to use
single backslashes since this is what VBA exopects.
Call RInterface.RunRFile("C:\Subodh\Prog\temprr.txt")
You also could omit Call and write
RInterface.RunRFile "C:\Subodh\Prog\temprr.txt"

If you were using VBA to run a command in R,
you would either need forward slashes

RInterface.RRun "source('C:/Subodh/Prog/temprr.txt')"

or (yes, this is strange) quadruple backslashes
RInterface.RRun "source('C:\\\\Subodh\\\\Prog\\\\temprr.txt')"

The reason is that when strings are parsed, backslashes indicate special
character, and backslahes themselves have to be written as double
backslashes. When things are parsed twice, this mechanism is applied
twice, therefore the 4 backslahes.

The simple rule:
If VBA needs a filename, use backslashes, if R needs a filename, use
forward slashes.

The reason for RunRFile to exist is that R and Excel may run on
different machines, and then RunRFile will use a file on the Excel
machine, whereas RunR "source(..." will use a file on the R machine.





[EMAIL PROTECTED] wrote:
> Try Call RInterface.RunRFile("C:/Subodh/Prog/temprr.txt") or Call
> RInterface.RunRFile("C:\Subodh\Prog\temprr.txt")
> 
> instead of Call RInterface.RunRFile("C:\\Subodh\\Prog\\temprr.txt")
> 
> Regards
> 
> Wayne
>  
> 
>     -----Original Message-----
>     *From:* [EMAIL PROTECTED]
>     [mailto:[EMAIL PROTECTED] Behalf Of
>     *Santosh Mishra
>     *Sent:* 06 October 2008 08:38
>     *To:* rcom-l@mailman.csd.univie.ac.at
>     *Subject:* [Rcom-l] Sourcing R code from VBA
> 
>     Dear Friends,
>      I am new to Rexcel, but I have worked in R for a while. I have a
>     problem in sourcing R code file from VBA.
>     Here is the code I am running in R.
>     ## R code below
>     library(np);
>     library(gam);
>     library(xlsReadWrite);
>     data("Italy");
>     attach(Italy);
>     X <- data.frame(year=ordered(year))
>     y <- data.frame(gdp)
>     bw <- npcdensbw(xdat=X, ydat=y, tol=.1, ftol=.1)
>     fhat <- npcdens(bws=bw);
>     utotd<-fhat$condens;
>     write.xls(totDat, "C:\\AAA.xls",colNames = FALSE,sheet = 1,from =
>     1,rowNames=NA ) ;
>     
> ############################################################################
>     XX<-cbind(rnorm(1008));
>     y1<-as.matrix(y);
>     gamformn<-formula(y1~s(XX));
>     nlin_fitn<-gam(formula = gamformn, family = gaussian, data =Italy,
>      na.action = na.exclude, control = list(epsilon =    0.0001,
>     bf.epsilon = 0.0001, maxit = 5000, bf.maxit = 1000, trace =
>     F),x=TRUE,y=TRUE)
>      tempjj2<-nlin_fitn$residuals;
> 
>     ## VBA macro used(the above code is stored in temprr.txt)
>     Sub Demo100()
>         RInterface.StartRServer      
>      Call RInterface.RunRFile("C:\\Subodh\\Prog\\temprr.txt")
>          RInterface.StopRServer
>     End Sub
> 
>      This is the error I am getting
> 
>     *Error-2147220502 in Module RExcel.Rserver
>     Error Running Expression
>     eval(parse(text="source(.rexcel..xtoavnn)"))*
> 
>     My hunch is that adding the GAM code is creating a problem. Because
>     when I use the np library (from beginning to ##########, it runs fine)
> 
>     Note that the  whole  code is running fine in R. Any help will be
>     highly appreciated.
>     Best regards,
>     Santosh
> 
>     Santosh Mishra
>     Assistant Professor
>     Department of Economics
>     Oregon State University
>     Corvallis, OR, 97330
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Rcom-l mailing list
> Rcom-l@mailman.csd.univie.ac.at
> http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l
> More information (including a Wiki) at http://rcom.univie.ac.at
> 
> 
> ------------------------------------------------------------------------
> 
> 
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.173 / Virus Database: 270.7.6/1709 - Release Date: 10/5/2008 
> 9:20 AM
> 

-- 
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459
_______________________________________________
Rcom-l mailing list
Rcom-l@mailman.csd.univie.ac.at
http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l
More information (including a Wiki) at http://rcom.univie.ac.at

Reply via email to