[Sciviews-commits] r136 - in pkg/svSocket: . R inst/etc man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat May 30 11:13:45 CEST 2009
Author: phgrosjean
Date: 2009-05-30 11:13:40 +0200 (Sat, 30 May 2009)
New Revision: 136
Added:
pkg/svSocket/R/sendSocketServer.R
pkg/svSocket/man/sendSocketServer.Rd
Modified:
pkg/svSocket/DESCRIPTION
pkg/svSocket/NAMESPACE
pkg/svSocket/NEWS
pkg/svSocket/inst/etc/SimpleClient.Tcl
pkg/svSocket/man/processSocket.Rd
pkg/svSocket/man/sendSocketClients.Rd
Log:
Added sendSocketServer() in svSocket
Modified: pkg/svSocket/DESCRIPTION
===================================================================
--- pkg/svSocket/DESCRIPTION 2009-05-29 09:26:22 UTC (rev 135)
+++ pkg/svSocket/DESCRIPTION 2009-05-30 09:13:40 UTC (rev 136)
@@ -3,7 +3,7 @@
Depends: R (>= 2.6.0), tcltk, svMisc
Description: Implements a simple socket server allowing to connect GUI clients to R
Version: 0.9-44
-Date: 2009-05-28
+Date: 2009-05-30
Author: Philippe Grosjean
Maintainer: Philippe Grosjean <phgrosjean at sciviews.org>
License: GPL (>= 2)
Modified: pkg/svSocket/NAMESPACE
===================================================================
--- pkg/svSocket/NAMESPACE 2009-05-29 09:26:22 UTC (rev 135)
+++ pkg/svSocket/NAMESPACE 2009-05-30 09:13:40 UTC (rev 136)
@@ -7,6 +7,7 @@
parSocket,
processSocket,
sendSocketClients,
+ sendSocketServer,
closeSocketClients,
startSocketServer,
stopSocketServer)
Modified: pkg/svSocket/NEWS
===================================================================
--- pkg/svSocket/NEWS 2009-05-29 09:26:22 UTC (rev 135)
+++ pkg/svSocket/NEWS 2009-05-30 09:13:40 UTC (rev 136)
@@ -2,6 +2,8 @@
== Changes in svSocket 0.9-43
* Example added in processSocket(), implementing a simple REPL
+* A new function, sendSocketServer() is added to send and evaluate commands from
+ one R instance (client) to another one (a R socket server)
== Changes in svSocket 0.9-43
Added: pkg/svSocket/R/sendSocketServer.R
===================================================================
--- pkg/svSocket/R/sendSocketServer.R (rev 0)
+++ pkg/svSocket/R/sendSocketServer.R 2009-05-30 09:13:40 UTC (rev 136)
@@ -0,0 +1,19 @@
+"sendSocketServer" <-
+function (text, serverhost = "localhost", serverport = 8888, ...)
+{
+ # This function connects to a R socket server, evaluates a command in it
+ # get results and closes the connection. See example for a client that
+ # connects for a longer time and sends several commands to the server
+ if (!capabilities("sockets"))
+ stop("R must support socket connections")
+ con <- socketConnection(host = serverhost, port = serverport,
+ blocking = FALSE, ...)
+ on.exit(close(con))
+ # <<<q>>> tells the R socket server to close the connection once results
+ # are send back to the client
+ writeLines(paste("<<<q>>>", text, sep = ""), con)
+ res <- ""
+ while(regexpr("\n\f", res) < 0)
+ res <- paste(res, readLines(con), sep = "", collapse = "\n")
+ return(sub("\n\f", "", res))
+}
Modified: pkg/svSocket/inst/etc/SimpleClient.Tcl
===================================================================
--- pkg/svSocket/inst/etc/SimpleClient.Tcl 2009-05-29 09:26:22 UTC (rev 135)
+++ pkg/svSocket/inst/etc/SimpleClient.Tcl 2009-05-30 09:13:40 UTC (rev 136)
@@ -10,7 +10,7 @@
set rsPort 8888 ;# port is arbitrarily fixed at 8888 for the R server
# Read data from a channel (the R socket server) and put it into stdout
-# this implements receiving and handling (viewing) a server reply
+# this implements receiving and handling (viewing) a server reply
proc read_sock {sock} {
if {[eof $sock] == 1 || [catch {gets $sock l}] || $l == "\f"} {
fileevent $sock readable {}
@@ -19,7 +19,7 @@
global eventLoop
set eventLoop "done"
} else {
- foreach {out in} [split $l "\n"] {
+ foreach {out in} [split $l "\n"] {
if {$out == "> " || $out == "+ "} {
puts -nonewline stdout $out
flush stdout
@@ -48,7 +48,7 @@
# Open the connection to the R socket server...
# this is a synchronous connection:
-# The command does not return until the server responds to the
+# The command does not return until the server responds to the
# connection request
set rsSock [socket $rsHost $rsPort]
@@ -78,11 +78,10 @@
puts "Connected to R socket server"
puts "...what you type should be send to R."
puts "Paste only one line of code at a time."
- puts " hit ctlr-c to close the connection."
+ puts " hit <CTRL-C> to close the connection."
# wait for and handle either socket or stdin events...
vwait eventLoop
puts "\nConnection with R is closed!"
}
-
Modified: pkg/svSocket/man/processSocket.Rd
===================================================================
--- pkg/svSocket/man/processSocket.Rd 2009-05-29 09:26:22 UTC (rev 135)
+++ pkg/svSocket/man/processSocket.Rd 2009-05-30 09:13:40 UTC (rev 136)
@@ -73,8 +73,8 @@
\author{Philippe Grosjean (\email{phgrosjean at sciviews.org})}
\seealso{ \code{\link{startSocketServer}}, \code{\link{sendSocketClients}},
- \code{\link[svMisc]{parSocket}}, \code{\link[svMisc]{Parse}},
- \code{\link[svMisc]{captureAll}} }
+ \code{\link{sendSocketServer}}, \code{\link[svMisc]{parSocket}},
+ \code{\link[svMisc]{Parse}}, \code{\link[svMisc]{captureAll}} }
\examples{
\dontrun{
Modified: pkg/svSocket/man/sendSocketClients.Rd
===================================================================
--- pkg/svSocket/man/sendSocketClients.Rd 2009-05-29 09:26:22 UTC (rev 135)
+++ pkg/svSocket/man/sendSocketClients.Rd 2009-05-30 09:13:40 UTC (rev 136)
@@ -20,6 +20,7 @@
\author{Philippe Grosjean (\email{phgrosjean at sciviews.org})}
-\seealso{ \code{\link{closeSocketClients}}, \code{\link{processSocket}} }
+\seealso{ \code{\link{closeSocketClients}}, \code{\link{processSocket}},
+ \code{\link{sendSocketServer}} }
\keyword{ IO }
Added: pkg/svSocket/man/sendSocketServer.Rd
===================================================================
--- pkg/svSocket/man/sendSocketServer.Rd (rev 0)
+++ pkg/svSocket/man/sendSocketServer.Rd 2009-05-30 09:13:40 UTC (rev 136)
@@ -0,0 +1,45 @@
+\name{sendSocketServer}
+\alias{sendSocketServer}
+
+\title{ Send data to an existing R socket server and disconnect. }
+
+\description{
+ The text is send to one R socket server and evaluated there as a command in
+ \code{.GlobalEnv}. Results (text as it should be printed on the console) is
+ returned to the client and the client then disconnects automatically.
+}
+
+\usage{
+sendSocketServder(text, serverhost = "localhost", serverport = 8888)
+}
+
+\arguments{
+ \item{text}{ The text (command) to send and evaluate in the server. }
+ \item{serverhost}{ The name or address of the host where the R socket server
+ is located. }
+ \item{serverport}{ The port of the R socket server. }
+}
+
+\author{Philippe Grosjean (\email{phgrosjean at sciviews.org})}
+
+\seealso{ \code{\link{sendSocketClients}}, \code{\link{closeSocketClients}},
+ \code{\link{processSocket}} }
+
+\examples{
+\dontrun{
+# Start a R socket server in an instance #1 of R
+# require(svSocket)
+# startSocketServer()
+#
+# Now, start an instance #2 of R on the same machine and do:
+require(svSocket)
+cat(sendSocketServer("ls()"))
+# You should read, at least, iris
+cat(sendSocketServer("x <- 2"))
+# Nothing happens, but switch to R #1 and type
+# x
+# to see the result
+}
+}
+
+\keyword{ IO }
More information about the Sciviews-commits
mailing list