[Remoterengine-commits] r114 - in pkg/RemoteREngine: R exec man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 8 14:29:33 CEST 2009


Author: romain
Date: 2009-09-08 14:29:33 +0200 (Tue, 08 Sep 2009)
New Revision: 114

Modified:
   pkg/RemoteREngine/R/start.server.R
   pkg/RemoteREngine/exec/remoterengine
   pkg/RemoteREngine/man/start.server.Rd
Log:
updated the start.server function to use rscript

Modified: pkg/RemoteREngine/R/start.server.R
===================================================================
--- pkg/RemoteREngine/R/start.server.R	2009-09-07 19:44:25 UTC (rev 113)
+++ pkg/RemoteREngine/R/start.server.R	2009-09-08 12:29:33 UTC (rev 114)
@@ -1,14 +1,23 @@
 
-start.server <- function( name = "test", port = 1099, registry.host = "localhost", run = TRUE, arguments = commandArgs(TRUE) ){
-	rscript    <- file.path( R.home(), "bin", "Rscript" )
-	script <- system.file( 'exec', 'remoterengine', package = 'RemoteREngine' )
-    
+start.server <- function( run = TRUE, arguments = commandArgs(TRUE) ){
+    rscript( "RemoteREngine", "remoterengine", run = run, arguments = arguments )
+}
+
+rscript <- function( package, script, arguments = commandArgs(TRUE), run = TRUE, dir = "exec" ){
+	
+	Rscript <- file.path( R.home(), "bin", "Rscript" )
+	script  <- system.file( dir, script, package = package )
+	if( !file.exists( script ) ){
+		stop( sprintf( "script '%s' does not exist", script) )
+	}
+	
 	arguments <- if( length( arguments ) == 0 ) "" else paste( arguments, collapse = " " )
-	cmd <- sprintf( '%s %s --name %s --port %d %s', rscript, script, name, port, arguments)
-    if( run ){
-        system( cmd )
-    } else{
-    	cmd
-    }
+	cmd <- sprintf( '"%s" "%s" %s', Rscript, script, arguments )
+	
+	if( run ){
+		system( cmd )
+	} else {
+		cmd
+	}
 }
 

Modified: pkg/RemoteREngine/exec/remoterengine
===================================================================
--- pkg/RemoteREngine/exec/remoterengine	2009-09-07 19:44:25 UTC (rev 113)
+++ pkg/RemoteREngine/exec/remoterengine	2009-09-08 12:29:33 UTC (rev 114)
@@ -114,9 +114,48 @@
 }
 # }}}
 
-cmd <- sprintf( 'java -cp "%s" -Djava.library.path="%s"  -Xmx1024M -Drjava.path="%s" -Drjava.class.path="%s" -Djava.rmi.server.codebase="%s" -Djava.security.policy="%s" org.rosuda.REngine.remote.server.REngineServer %s', 
-	CP, LD_LIBRARY_PATH, RJAVA, RJAVA_CP, codebase, policy, arguments )
+# {{{ these functions might move to rJava at some point
+java.home <- function( set = FALSE ){
+	JAVA_HOME <- Sys.getenv( "JAVA_HOME", unset = "" )
+	if( JAVA_HOME != "" ){
+		.jinit()
+		JAVA_HOME <- .jcall( "java.lang.System", "S", "getProperty", "java.home" )
+		if( set ) Sys.setenv( JAVA_HOME = JAVA_HOME )
+	}
+	JAVA_HOME
+}
 
+java.cmd <- function( JAVA_HOME = java.home(), set = FALSE ){
+	JAVACMD <- Sys.getenv( "JAVACMD", unset = "" )
+	if( JAVACMD == "" ){
+		# IBM's JDK on AIX uses strange locations for the executables
+	    if( file.exists( cmd <- file.path( JAVA_HOME, "jre", "sh", "java" ) ) ){
+	    	JAVACMD <- cmd
+	    } else if( file.exists( cmd <- file.path( JAVA_HOME, "jre", "bin", "java" ) ) ){
+	    	JAVACMD <- cmd
+	    } else if( file.exists( cmd <- file.path( JAVA_HOME, "bin", "java" ) ) ){
+	    	JAVACMD <- cmd
+	    } else if( file.exists( cmd <- file.path( JAVA_HOME, "jre", "bin", "java.exe" ) ) ){
+	    	JAVACMD <- cmd
+	    } else if( file.exists( cmd <- file.path( JAVA_HOME, "bin", "java.exe" ) ) ){
+	    	JAVACMD <- cmd
+	    } else if( file.exists( cmd <- file.path( JAVA_HOME, "jre", "bin", "javaw.exe" ) ) ){
+	    	JAVACMD <- cmd
+	    } else if( file.exists( cmd <- file.path( JAVA_HOME, "bin", "javaw.exe" ) ) ){
+	    	JAVACMD <- cmd
+	    } else {
+	    	stop( paste( "could not find java command, is java installed in : '" , JAVA_HOME , "' ?" ) )
+		}
+	}
+	if( set ) Sys.setenv( JAVACMD = JAVACMD )
+	JAVACMD
+}
+JAVACMD <- java.cmd( )
+# }}}
+
+cmd <- sprintf( '"%s" -cp "%s" -Djava.library.path="%s"  -Xmx1024M -Drjava.path="%s" -Drjava.class.path="%s" -Djava.rmi.server.codebase="%s" -Djava.security.policy="%s" org.rosuda.REngine.remote.server.REngineServer %s', 
+	JAVACMD, CP, LD_LIBRARY_PATH, RJAVA, RJAVA_CP, codebase, policy, arguments )
+
 system( cmd, wait = TRUE )
 # cat( cmd, "\n" )
 # }}}

Modified: pkg/RemoteREngine/man/start.server.Rd
===================================================================
--- pkg/RemoteREngine/man/start.server.Rd	2009-09-07 19:44:25 UTC (rev 113)
+++ pkg/RemoteREngine/man/start.server.Rd	2009-09-08 12:29:33 UTC (rev 114)
@@ -5,21 +5,25 @@
 Utility to start the R server
 }
 \description{
-Utility to start the R server
+	Utility to start the R server. This calls the script \code{remoterengine}
+	contained in the \code{exec} directory of the package. See examples below
 }
 \usage{
-start.server(name = "test", port = 1099, registry.host = "localhost", 
-	run = TRUE, arguments = commandArgs(TRUE))
+start.server(run = TRUE, arguments = commandArgs(TRUE))
 }
 \arguments{
-  \item{name}{name of the R engine in the rmi registry}
-  \item{port}{port used by the rmi registry}
-  \item{registry.host}{hostname where the rmi registry runs}
   \item{run}{logical, if TRUE the command is run. Otherwise it is just returned}
   \item{arguments}{Additional arguments, typically used by the command line}
 }
 \author{
 Romain Francois <francoisromain at free.fr>
 }
+\examples{
+# the script that gets called
+script <- system.file( "exec", "remoterengine", package = "RemoteREngine" )
+
+# make sure the file exists
+stopifnot( file.exists( script ) )
+}
 \keyword{manip}
 



More information about the Remoterengine-commits mailing list