[R] run query using rexcel runrfile and rodbc sql query
BrianCBolt
briancbolt at gmail.com
Fri Jan 30 18:25:51 CET 2009
Hi,
I'm using R-2.8.1 for windows. I wrote a script calls the RODBC
package to run sql queries against an oracle database. It runs fine
when run from the rconsole and returns a data.frame with a summary for
a set of experiments. I want to run this script using the
rinterface.RunRFile command in an excel plugin, using the rexcel
package. When I run the code from my excel plugin I get an error:
"Error -2147220502 in Module RExcel.RServer Error running expression
eval(parse(text="source(.rexcel..hzpouai)"))"
Here is my excel plugin code:
rinterface.StartRServer
rinterface.RRun "setwd(""C:/Documents and Settings/bbolt/
Desktop"")"
ChDir "C:/Documents and Settings/bbolt/Desktop"
rinterface.RunRFile "Script.r"
It works fine if Script.r is something simple like:
Text <- data.frame(Hello="Hello")
But will give me the error when Script.R is something like:
inSet <- "TEST0000853"
library("RODBC")
query <- function(qu){
con <-
odbcConnect
("Development
",uid="username",pwd="password",believeNRows=FALSE,rows_at_time=50)
sqlQuery(con,qu)
}
qu <- paste("m.parentid as SET from setmap m where m.childid in
(select t.experiment from experimentsets t where
t.setname='",inSET,"')",sep="")
ExperimentSet <- as.character(query(qu)[,1])
The error only occurs when I call my "query" function. Does anyone
know if there is a way to run sql queries in this manner?
More information about the R-help
mailing list