Hi, I am running a test to call an R script with in excel using VBA. My VBA code is shown bellow. The middle section of this mail also includes the content of my Rscript. The bottom part shows the error message form the R console. It seems that Excel is opening the R console without any problems. The problem I am seeing is that Rinterface.RRun instruction is interpreting the "\T" part of the path as an R command. It does not recognize the "X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home models\" as a one single string, or path. Any ideas how can I fix the problem? Thanks ,' Jorge VB code Sub tester() Rinterface.StartRServer Rinterface.RRun ("source('X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home models\toto.R')") Rinterface.StopRServer End Sub "R cript code toto.R" path = getwd() setwd(path) a = 5 b=5 x = matrix(rnorm(a*b),a,b) a = 5 b=5 y = matrix(rnorm(a*b),a,b) z = x %*% y savefile = paste(path,"/","testresults.csv",sep="") write.csv(z, file = savefile) Rconsole message Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. Loading required package: rcom Loading required package: rscproxy Error: '\T' is an unrecognized escape in character string starting "source('X:\T"> >Jorge Nieves [[alternative HTML version deleted]]
Use "/" instead of "\" in the path. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Jorge Nieves <jorge.nieves@moorecap.com> wrote: Hi, I am running a test to call an R script with in excel using VBA. My VBA code is shown bellow. The middle section of this mail also includes the content of my Rscript. The bottom part shows the error message form the R console. It seems that Excel is opening the R console without any problems. The problem I am seeing is that Rinterface.RRun instruction is interpreting the "\T" part of the path as an R command. It does not recognize the "X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home models\" as a one single string, or path. Any ideas how can I fix the problem? Thanks ,' Jorge VB code Sub tester() Rinterface.StartRServer Rinterface.RRun ("source('X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home models\toto.R')") Rinterface.StopRServer End Sub "R cript code toto.R" path = getwd() setwd(path) a = 5 b=5 x = matrix(rnorm(a*b),a,b) a = 5 b=5 y = matrix(rnorm(a*b),a,b) z = x %*% y savefile = paste(path,"/","testresults.csv",sep="") write.csv(z, file = savefile) Rconsole messa ge Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. Loading required package: rcom Loading required package: rscproxy Error: '\T' is an unrecognized escape in character string starting "source('X:\T" > > Jorge Nieves [[alternative HTML version deleted]]_____________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
Jorge, This looks like an R on Windows problem, it is unrelated to VBA. You have the statement ("source('X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home models\toto.R')") which is invalid R. You need to use either forward slashes or double-back-slashes in R commands. See the R for Windows FAQ 2.16. Further RCOM questions should be addressed to the rcom list. You can sign up at rcom.univie.ac.at Rich On Fri, Apr 1, 2011 at 10:12 AM, Jorge Nieves <jorge.nieves@moorecap.com>wrote:> > Hi, > > I am running a test to call an R script with in excel using VBA. My VBA > code is shown bellow. The middle section of this mail also includes the > content of my Rscript. The bottom part shows the error message form the > R console. > > It seems that Excel is opening the R console without any problems. > > The problem I am seeing is that Rinterface.RRun instruction is > interpreting the "\T" part of the path as an R command. It does not > recognize the "X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home > models\" as a one single string, or path. > > > Any ideas how can I fix the problem? > > Thanks ,' > > Jorge > > > VB code > Sub tester() > > Rinterface.StartRServer > > Rinterface.RRun > ("source('X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home > models\toto.R')") > > Rinterface.StopRServer > > End Sub > > > > "R cript code toto.R" > path = getwd() > setwd(path) > a = 5 > b=5 > x = matrix(rnorm(a*b),a,b) > a = 5 > b=5 > > y = matrix(rnorm(a*b),a,b) > z = x %*% y > savefile = paste(path,"/","testresults.csv",sep="") > write.csv(z, file = savefile) > > > > > > Rconsole message > > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for an HTML browser interface to help. > Type 'q()' to quit R. > > Loading required package: rcom > Loading required package: rscproxy > Error: '\T' is an unrecognized escape in character string starting > "source('X:\T" > > > > > Jorge Nieves > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
On 01-04-2011, at 16:12, Jorge Nieves wrote:> > Hi, > > I am running a test to call an R script with in excel using VBA. My VBA > code is shown bellow. The middle section of this mail also includes the > content of my Rscript. The bottom part shows the error message form the > R console. > > It seems that Excel is opening the R console without any problems. > > The problem I am seeing is that Rinterface.RRun instruction is > interpreting the "\T" part of the path as an R command. It does not > recognize the "X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home > models\" as a one single string, or path. > > > Any ideas how can I fix the problem? > > Thanks ,' > > Jorge > > > VB code > Sub tester() > > Rinterface.StartRServer > > Rinterface.RRun > ("source('X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home > models\toto.R')") > > Rinterface.StopRServer > > End Sub > > > > "R cript code toto.R" > path = getwd() > setwd(path) > a = 5 > b=5 > x = matrix(rnorm(a*b),a,b) > a = 5 > b=5 > > y = matrix(rnorm(a*b),a,b) > z = x %*% y > savefile = paste(path,"/","testresults.csv",sep="") > write.csv(z, file = savefile) > > Rconsole message > > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for an HTML browser interface to help. > Type 'q()' to quit R. > > Loading required package: rcom > Loading required package: rscproxy > Error: '\T' is an unrecognized escape in character string starting > "source('X:\T"R is just telling you that it doesn't recognize \T as a valid escape sequence in a character string. See R for Windows FAQ 2.16 and 5.1. Use \\ instead of a single \ as path separator or use the forward slash /. Berend
Jorge: You can run save your scripts in the same folder where your wokbook is and run it like this: Sub Scatter()???????????????????? Call rinterface.StartRServer 'Put the dataframe into R ????Call rinterface.PutDataframe("scatter", DownRightFrom(Range("RData!A1")), WithRowNames:=False) Call rinterface.RRun("attach(scatter)") 'Run the RScatter script rinterface.RunRFile ThisWorkbook.Path & "\RScatter.r" Call rinterface.StopRServer End Sub I ? Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx ----- Original Message ----> From: Jorge Nieves <jorge.nieves at moorecap.com> > To: r-help at stat.math.ethz.ch > Sent: Fri, April 1, 2011 7:12:39 AM > Subject: [R] Rexcel path problem > > > Hi, > > I am running a test to call an R script with in excel using VBA. My VBA > code is shown bellow. The middle section of this mail also includes the > content of my Rscript.? The bottom part shows the error message form the > R console. > > It seems that Excel is? opening the R console without any problems. > > The problem I am seeing is that Rinterface.RRun? instruction is > interpreting the "\T" part of the path as an R command. It does not > recognize the "X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home > models\" as a one single string, or path. > > > Any ideas how can I fix the problem? > > Thanks ,' > > Jorge > > > VB code > Sub tester() > > ? ? Rinterface.StartRServer > > ? ? Rinterface.RRun > ("source('X:\Trading\Energy\JorgeSpace\TMPholder\cpixe\home > models\toto.R')")? ? > > ? ? Rinterface.StopRServer > ? ? > End Sub > > > > "R cript code toto.R" > path = getwd() > setwd(path) > a = 5 > b=5 > x = matrix(rnorm(a*b),a,b) > a = 5 > b=5 > > y = matrix(rnorm(a*b),a,b) > z = x %*% y > savefile = paste(path,"/","testresults.csv",sep="") > write.csv(z, file = savefile) > > > > > > Rconsole message > > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for an HTML browser interface to help. > Type 'q()' to quit R. > > Loading required package: rcom > Loading required package: rscproxy > Error: '\T' is an unrecognized escape in character string starting > "source('X:\T" > > > > > Jorge Nieves > > > > ??? [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >