rjava - R source file from RConnection (JRI) "could not find function" -


i'm trying source r script file org.rosuda.rengine.rserve.rconnection , calling function script, getting, "error: not find function "main".

start rserve terminal

> require(rserve) loading required package: rserve > rserve() starting rserve...  "c:\users\slenzi\docume~1\r\win-li~1\3.3\rserve\libs\x64\rserve.exe" > rserve: ok, ready answer queries. error: not find function "main" 

external script rdbctest1.r

require(rjdbc)  main <- function() {     jdbcdriver <- jdbc(driverclass = dbdriverclass, classpath = dbdriverpath)     jdbcconnection <- dbconnect(jdbcdriver, dburl, dbuser, dbpwd)     dbresult <- dbgetquery(jdbcconnection, dbquery)     dbdisconnect(jdbcconnection)     return(dbresult) } 

java code

import org.rosuda.rengine.rexp; import org.rosuda.rengine.rexpmismatchexception; import org.rosuda.rengine.rengine; import org.rosuda.rengine.rengineexception; import org.rosuda.rengine.rlist; import org.rosuda.rengine.rserve.rconnection; import org.rosuda.rengine.rserve.rserveexception;  rexp result = null; rconnection c = null; try {      c = new rconnection();      string driverpath = "c:/temp/ojbdc6.jar";     string scriptpath = "c:/temp/rdbctest1.r";      c.assign("dbuser", "foo");     c.assign("dbpwd", "******");// commented out     c.assign("dburl", "jdbc:oracle:thin:@myhost:1511:ecogtst");     c.assign("dbdriverclass", "oracle.jdbc.driver.oracledriver");     c.assign("dbdriverpath", driverpath);             // assign query execute     c.assign("dbquery", "select count(*) prs.members");                  string evalsource = string.format("try(source(\"%s\", local=true), silent=true)", scriptpath);      c.eval("evalsource");      // debug     result = c.eval("ls()");     logger.info("rexp debug => " + result.todebugstring());               result = c.eval("main()");  } catch (rserveexception e) {     logger.error("error running script test, " + e.getmessage()); } {     if(c != null){         c.close();     } } 

output

evaluating => try(source("c:/temp/rdbctest1.r", local=true), silent=true) rexp debug => org.rosuda.rengine.rexpstring@61c6bc05[6]{"dbdriverclass","dbdriverpath","dbpwd","dbquery","dburl","dbuser"}  error: not find function "main" error running oracle script test, eval failed, request status: error code: 127 

running script directly r terminal works fine. when ran rconnection can see values of variables assign (c.assign(...)) not main() function sourced script.

what missing in regards sourcing script? how can access function script?

thanks.

** update **

i got following work, if has idea why source() doesn't seem work in example above, please let me know!

rconnection c = ... rexp x = c.parseandeval("try(eval(parse(file=\"c:/temp/rdbctest3.r\")), silent=true)") 


Comments