[Sciviews-commits] r289 - in pkg/svGUI: . R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Sep 6 18:29:38 CEST 2010
Author: phgrosjean
Date: 2010-09-06 18:29:37 +0200 (Mon, 06 Sep 2010)
New Revision: 289
Added:
pkg/svGUI/R/httpServer.R
pkg/svGUI/man/httpServer.Rd
Modified:
pkg/svGUI/DESCRIPTION
pkg/svGUI/NAMESPACE
pkg/svGUI/NEWS
pkg/svGUI/R/koCmd.R
pkg/svGUI/R/svGUI-internal.R
pkg/svGUI/inst/CITATION
pkg/svGUI/man/koCmd.Rd
Log:
Slight refactoring and first version of the HTTP server
Modified: pkg/svGUI/DESCRIPTION
===================================================================
--- pkg/svGUI/DESCRIPTION 2010-09-06 16:28:53 UTC (rev 288)
+++ pkg/svGUI/DESCRIPTION 2010-09-06 16:29:37 UTC (rev 289)
@@ -1,13 +1,14 @@
Package: svGUI
Type: Package
Title: SciViews GUI API - Functions to manage GUI client
-Depends: R (>= 2.6.0)
-Imports: svMisc, svSocket (>= 0.9-48)
+Depends: R (>= 2.11.0), svMisc
+Imports: tools
+Suggests: svSocket (>= 0.9-48)
SystemRequirements: Komodo Edit (http://www.openkomodo.com), SciViews-K (http://www.sciviews.org/SciViews-K)
Description: Functions to manage the GUI client, like Komodo with the
SciViews-K extension
-Version: 0.9-47
-Date: 2010-04-29
+Version: 0.9-48
+Date: 2010-08-30
Author: Philippe Grosjean
Maintainer: Philippe Grosjean <phgrosjean at sciviews.org>
License: GPL-2
Modified: pkg/svGUI/NAMESPACE
===================================================================
--- pkg/svGUI/NAMESPACE 2010-09-06 16:28:53 UTC (rev 288)
+++ pkg/svGUI/NAMESPACE 2010-09-06 16:29:37 UTC (rev 289)
@@ -1,7 +1,13 @@
-import(svMisc, svSocket)
+import(svMisc, tools)
export(guiInstall,
guiUninstall,
guiRefresh,
guiAutoRefresh,
- koCmd)
+ koCmd,
+ startHttpServer,
+ stopHttpServer,
+ HttpServerPort,
+ HttpServerName,
+ HttpClientsNames,
+ parHttp)
Modified: pkg/svGUI/NEWS
===================================================================
--- pkg/svGUI/NEWS 2010-09-06 16:28:53 UTC (rev 288)
+++ pkg/svGUI/NEWS 2010-09-06 16:29:37 UTC (rev 289)
@@ -1,6 +1,32 @@
= svGUI News
+== Changes in svGUI 0.9-48
+
+* koCmd() now should prepend <<<js>>> to the JavaScript code to get it evaluated
+ in Komodo (starting with SciViews-K 0.9-18). Komodo now also accepts RJsonP
+ strings, prepended with <<<rjson>>>. If there is no code prepended to the
+ string send to Komodo, it is just printed in the local R console.
+ A new 'type' argument specifies what kind of string we send to Komodo.
+
+* The R http server is modified to work with either RJsonP calls, or with plain
+ text exchange, as the SciViews socket server works. RJsonP objects returned
+ use list() to create lists, but also structures or new S4 objects.
+
+
+== Changes in svGUI 0.9-47
+
+* A new series of function to communication with a SciViews GUI client like
+ Komodo/SciViews-K by using the R http help server is added. It offers a
+ tcltk-free alternative to the svSocket server.
+
+* The package no longer starts the socket server implemented in svSocket and it
+ does not import svSocket any more. As the HTTP server is an alternative, one
+ could now choose to run SciViews communication through the HTTP server without
+ using svSocket, and thus, without starting Tcl/Tk any more.
+
+
== Changes in svGUI 0.9-46
+
* Use of svTaskCallbackManager() of svSocket >= 0.9-48 to register task
callback that are also executed after each R code send by socket clients.
Added: pkg/svGUI/R/httpServer.R
===================================================================
--- pkg/svGUI/R/httpServer.R (rev 0)
+++ pkg/svGUI/R/httpServer.R 2010-09-06 16:29:37 UTC (rev 289)
@@ -0,0 +1,383 @@
+# A SciViews R server using HTTP R help server and JSONP for communcation
+# Copyright (c) 2010, Ph. Grosjean (phgrosjean at sciviews.org)
+# Use a HTTP request like this in the client:
+# http://127.0.0.1:8888/custom/SciViews?msg&callback
+# We must return something like (in a correct RJSONp object):
+#<callback>({"result":{"String 1", "String 2", "..."}, "options":"<options>",
+#"name":"<server.name>","port":"<port>"})
+# Another (simpler) way to call it is by using
+# http://127.0.0.1:8888/custom/SciViews?msg
+# and in this case, the client must manage the simple string returned
+
+# Get the list of all names of clients that already connected to the http server
+"HttpClientsNames" <- function ()
+ sub("^HttpClient_", "", ls(envir = TempEnv(), pattern = "^HttpClient_"))
+
+# Get or change the port of the http server
+"HttpServerPort" <- function (port)
+{
+ if (!missing(port)) {
+ port <- as.integer(round(port[1]))
+ # This port is stored in 'ko.serve' option
+ options(ko.serve = port)
+ # If the server is running on another port, restart it now
+ curport <- tools:::httpdPort
+ if (curport > 0 && curport != port) startHttpServer(port = port)
+ return(port)
+ } else { # Get the server port
+ port <- getOption("ko.serve")
+ if (is.null(port)) port <- 8888 else port <- as.integer(round(port[1]))
+ return(port)
+ }
+}
+
+# Get or change the name of the HTTP server
+"HttpServerName" <- function (name)
+{
+ if (!missing(name)) {
+ if (!is.character(name)) stop("'name' must be a string!")
+ name <- as.character(name)[1]
+ # This name is stored in the option R.id
+ options(R.id = name)
+ return(name)
+ } else { # Get the server name
+ name <- getOption("R.id")
+ if (is.null(name)) name <- "R"
+ return(name)
+ }
+}
+
+# Get or change http server options
+"parHttp" <- function (client, ...)
+{
+ if (missing(client)) client <- "default" else client <- as.character(client)[1]
+
+ # Set or get parameters for a given HTTP client
+ serverport <- HttpServerPort()
+
+ # No attempt is made to make sure this client exists
+ sc <- paste("HttpClient", client, sep = "_")
+ if (!exists(sc, envir = TempEnv(), inherits = FALSE,
+ mode = "environment")) {
+ # Create a new environment with default values
+ e <- new.env(parent = TempEnv())
+ e$client <- client
+ e$serverport <- serverport
+ e$prompt <- ":> " # Default prompt
+ e$continue <- ":+ " # Default continuation prompt
+ e$code <- "" # Current partial code for multiline mode
+ e$last <- "" # String to add at the end of evaluations
+ e$echo <- FALSE # Don't echo commands to the console
+ e$flag <- FALSE # Do not flag pieces of code (not used yet!)
+ e$multiline <- TRUE # Allow for multiline code
+ e$bare <- TRUE # Always start in "bare" mode
+ # Note: in bare mode, all other parameters are inactive!
+ # and assign it to TempEnv
+ assign(sc, e, envir = TempEnv())
+ } else e <- get(sc, envir = TempEnv(), mode = "environment")
+
+ # Change or add parameters if they are provided
+ args <- list(...)
+ if (l <- length(args)) {
+ change.par <- function (x, val, env) {
+ if (is.null(x)) return(FALSE) # Do nothing without a valid name
+ if (is.null(val)) {
+ suppressWarnings(rm(list = x, envir = env)) # Remove it
+ return(TRUE)
+ }
+ env[[x]] <- val # Add or change this variable in the environment
+ return(TRUE)
+ }
+ n <- names(args)
+ res <- rep(TRUE, l)
+ for (i in seq_len(l)) res[i] <- change.par(n[i], args[[i]], e)
+ if (any(!res)) warning("Non named arguments are ignored")
+ }
+
+ # If serverport has changed, update it now
+ if (e$serverport != serverport) e$serverport <- serverport
+
+ # Return e invisibly
+ return(invisible(e))
+}
+
+# Stop the SciViews and R HTTP server and eliminate all tracks
+"stopHttpServer" <- function (remove.clients = FALSE) {
+ # Eliminate the SciViews custom process function for HTTP server
+ e <- tools:::.httpd.handlers.env
+ if ("SciViews" %in% ls(envir = e)) rm(list = "SciViews", envir = e)
+
+ # Do we also remove persistent data for clients?
+ if (isTRUE(remove.clients))
+ rm(list = ls(envir = TempEnv(), pattern = "^HttpClient_"),
+ envir = TempEnv())
+
+ # Stop the HTTP deamon
+ tools::startDynamicHelp(FALSE)
+}
+
+# (Re)start HTTP help server on the choosen port
+# TODO: allowing asking and returning results in the RJSON object
+# TODO: conversion to UTF-8 encoding of the returned string
+"startHttpServer" <- function (port = HttpServerPort(),
+name = HttpServerName())
+{
+ if (!is.character(name)) stop("'name' must be a string!")
+ name <- as.character(name)[1]
+
+ # The port on which we want to run it
+ if (!is.numeric(port[1]) || port[1] < 1)
+ stop("'port' must be a positive integer!")
+ port <- as.integer(round(port[1]))
+ # The port on which the server currently runs
+ curport <- tools:::httpdPort
+
+ # Can we run the server?
+ if (curport == -1L || nzchar(Sys.getenv("R_DISABLE_HTTPD")))
+ stop("R http server is disabled or cannot start")
+
+ # If it is currently running, stop it now
+ if (curport != 0L) {
+ if (curport != port)
+ warning("R http server currently running on port ", curport,
+ " and is restarted on port ", port, immediate. = TRUE)
+ curport <- stopHttpServer()
+ }
+
+ # Start the http server on the right port
+ if (curport == 0L) {
+ oports <- getOption("help.ports")
+ (on.exit(options(help.ports = oports)))
+ options(help.ports = port)
+ curport <- tools::startDynamicHelp()
+ } else stop("Unable to start the http server")
+
+ # Is the HTTP server running on the right port now?
+ if (curport == port) {
+ # Set the name of the HTTP server (for easier identification)
+ HttpServerName(name)
+
+ # Install the SciViews function that will process our requests
+ e <- tools:::.httpd.handlers.env
+ e[["SciViews"]] <- function (path, query, body) {
+ # Analyze the query: command + callback
+ #cat(query, "\n", sep = " -- ")
+ msg <- query[1]
+ l <- length(query)
+ if (l > 1) callback <- query[l] else callback <- NULL
+
+ # Get the server name and port, and R encoding
+ servername <- HttpServerName()
+ serverport <- HttpServerPort()
+
+ # Process the command in a similar way as processSocket() does
+ # in the svSocket package... but return a RJSONP object if callback is not NULL
+ # We use a custom function here to create this object faster than
+ # by converting an R object to RJSON
+ Rjsonp <- function (res, callback) {
+ # If no echo, return only a basic RJSONP object
+ if (!returnResults || is.null(res)) {
+ obj <- paste(callback,
+ '(list("result" := NA, ',
+ '"options" := list("echo" := FALSE), "name" := "',
+ servername, '", "port" := ', serverport, '))', sep = "")
+ } else {
+ # Return a more consistent RJSONP object
+ # Format main client options as a RJSON object
+ options <- paste('list("echo" := ', pars$echo,
+ ', "bare" := ', pars$bare,
+ ', "partial" := ', (pars$code != ""), ')', sep = "")
+
+ # Replace \n by \\n, etc. in res
+ #res <- gsub("\n", "\\n", res, fixed = TRUE)
+ res <- encodeString(res, quote = '"')
+
+ # Check encoding and provide it if it is not UTF-8
+ cs <- localeToCharset()[1]
+ if (cs != "UTF-8") {
+ encode <- paste (', "encoding" := "', cs, '"', sep = "")
+ } else encode <- ""
+
+ # Format the answer as a RJSONP object and return it
+ obj <- paste(callback, '(list("result" := c(',
+ paste(shQuote(res, type = "cmd"), collapse = ", "),
+ '), "options" := ', options,
+ ', "name" := "', servername,
+ '", "port" := ', serverport, encode, '))', sep = "")
+ }
+ #cat(obj, "\n")
+ return(list(obj))
+ }
+
+ # Do we receive an <<<id=myID>>> sequence (name of the client)?
+ if (regexpr("^<<<id=[a-zA-Z0-9]+>>>", msg) > 0) {
+ # get the identifier
+ client <- sub("^<<<id=([a-zA-Z0-9]+)>>>.*$", "\\1", msg)
+ # and eliminate that sequence
+ msg <- sub("^<<<id=[a-zA-Z0-9]+>>>", "", msg)
+ } else {
+ # The client name is simply 'default'
+ client <- "default"
+ }
+
+ # Do we receive <<<esc>>>? => break (currently, only break multiline mode)
+ if (substr(msg, 1, 9) == "<<<esc>>>") {
+ pars <- parHttp(client, code = "") # Reset multiline code
+ msg <- substr(msg, 10, 1000000)
+ }
+
+ # Replace <<<n>>> by \n (for multiline code)
+ msg <- gsub("<<<n>>>", "\n", msg)
+
+ # Replace <<<s>>> by the corresponding client identifier and server port
+ msg <- gsub("<<<s>>>", paste('"', client, '", ', serverport,
+ sep = ""), msg)
+
+ hiddenMode <- FALSE
+ returnResults <- TRUE
+ # If msg starts with <<<Q>>> or <<<q>>>, then disconnect server
+ # before or after evaluation of the command, respectively
+ # Since we always disconnect AFTER with http server, these options
+ # have no effect here. They are used with the socket server only
+ # If msg starts with <<<e>>>, evaluate command in the console and
+ # disconnect
+ # If msg starts with <<<h>>> or <<<H>>>, evaluate in hidden mode
+ # and disconnect
+ startmsg <- substr(msg, 1, 7)
+ if (startmsg == "<<<Q>>>") {
+ msg <- substr(msg, 8, 1000000)
+ returnResults <- FALSE
+ } else if (startmsg == "<<<q>>>") {
+ msg <- substr(msg, 8, 1000000)
+ parHttp(client, last = "")
+ } else if (startmsg == "<<<e>>>") {
+ msg <- substr(msg, 8, 1000000)
+ # We just configure the server correctly
+ parHttp(client, bare = FALSE, echo = TRUE, prompt = ":> ",
+ continue = ":+ ", multiline = TRUE, last = "")
+ # Add a command to the command history
+ #timestamp("my R command", "", "", quiet = TRUE)
+ } else if (startmsg == "<<<h>>>") {
+ msg <- substr(msg, 8, 1000000)
+ # Do not echo command on the server (silent execution)
+ hiddenMode <- TRUE
+ parHttp(client, bare = TRUE, last = "")
+ } else if (startmsg == "<<<H>>>") {
+ msg <- substr(msg, 8, 1000000)
+ # Do not echo command on the server
+ hiddenMode <- TRUE
+ returnResults <- FALSE
+ parHttp(client, bare = TRUE)
+ } else if (startmsg == "<<<u>>>") {
+ msg <- substr(msg, 8, 1000000)
+ # Silent execution, nothing is returned to the client
+ # (but still echoed to the server)
+ hiddenMode <- FALSE
+ returnResults <- FALSE
+ parHttp(client, bare = TRUE)
+ }
+
+ # Get parameters for the client
+ pars <- parHttp(client)
+ if (Bare <- pars$bare) {
+ Prompt <- ""
+ Continue <- ""
+ Echo <- FALSE
+ } else {
+ Prompt <- pars$prompt
+ Continue <- pars$continue
+ Echo <- pars$echo
+ }
+ if (!hiddenMode) {
+ if (Echo) {
+ if (pars$code == "") Pre <- Prompt else Pre <- Continue
+ cat(Pre, msg, "\n", sep = "")
+ }
+ # Add previous content if we were in multiline mode
+ msg <- paste(pars$code, msg, sep = "\n")
+ pars$code <- "" # This changes the original data too!
+ }
+
+ # Parse the R code
+ expr <- Parse(msg)
+ # Is it a wrong code?
+ if (inherits(expr, "try-error")) {
+ res <- paste(ngettext(1, "Error: ", "", domain = "R"),
+ sub("^[^:]+: ([^\n]+)\n[0-9]+:(.*)$", "\\1\\2", expr), sep = "")
+ if (Echo) cat(res)
+ if (is.null(callback)) {
+ return(paste(res, pars$last, Prompt, sep = ""))
+ } else {
+ return(Rjsonp(paste(res, pars$last, Prompt, sep = ""), callback))
+ }
+ }
+ # Is it incomplete code?
+ if (!is.expression(expr)) {
+ # Is multiline mode allowed?
+ if (!Bare && pars$multiline) {
+ pars$code <- msg
+ if (is.null(callback)) {
+ if (returnResults) {
+ return(paste(pars$last, Continue, sep = ""))
+ } else return(NULL)
+ } else {
+ if (returnResults) {
+ return(Rjsonp(paste(pars$last, Continue, sep = ""), callback))
+ } else return(Rjsonp(NULL, callback))
+ }
+ } else { # Multimode not allowed
+ res <- paste(gettext("Error: incomplete command in single line mode"),
+ "\n", sep = "")
+ if (Echo) cat(res)
+ if (is.null(callback)) {
+ if (returnResults) {
+ return(paste(res, pars$last, Prompt, sep = ""))
+ } else return(NULL)
+ } else {
+ if (returnResults) {
+ return(Rjsonp(paste(res, pars$last, Prompt, sep = ""), callback))
+ } else return(Rjsonp(NULL, callback))
+ }
+ }
+ }
+ # Freeze parameters (unlinks from the environment)
+ pars <- as.list(pars)
+ # Is it something to evaluate?
+ if (length(expr) < 1) {
+ if (is.null(callback)) {
+ return(paste(pars$last, Prompt, sep = ""))
+ } else {
+ return(Rjsonp(paste(pars$last, Prompt, sep = ""), callback))
+ }
+ }
+ # Correct code,... we evaluate it
+ ## TODO: here, evaluate line by line and return result immediately!
+ results <- captureAll(expr)
+ # Should we run taskCallbacks?
+ if (!hiddenMode) {
+ h <- getTemp(".svTaskCallbackManager", default = NULL,
+ mode = "list")
+ if (!is.null(h)) h$evaluate()
+ }
+ # Collapse and add last and the prompt at the end
+ results <- paste(results, collapse = "\n")
+ if (Echo) cat(results)
+ if (!returnResults) {
+ if (is.null(callback)) {
+ return(NULL)
+ } else {
+ return(Rjsonp(NULL, callback))
+ }
+ }
+ Prompt <- if (pars$bare) "" else pars$prompt
+ results <- paste(results, pars$last, Prompt, sep = "")
+ # Return the results in plain text, or RJSONP object
+ if (is.null(callback)) {
+ return(results)
+ } else {
+ return(Rjsonp(results, callback))
+ }
+ }
+ }
+ return(invisible(curport))
+}
Modified: pkg/svGUI/R/koCmd.R
===================================================================
--- pkg/svGUI/R/koCmd.R 2010-09-06 16:28:53 UTC (rev 288)
+++ pkg/svGUI/R/koCmd.R 2010-09-06 16:29:37 UTC (rev 289)
@@ -1,9 +1,11 @@
"koCmd" <-
function (cmd, data = NULL, async = FALSE, host = getOption("ko.host"),
- port = getOption("ko.port"), timeout = 1)
+ port = getOption("ko.port"), timeout = 1, type = c("js", "rjsonp", "output"),
+ pad = NULL, ...)
{
- if (is.null(host)) host <- "localhost" # Default value
+ type <- match.arg(type)
+ if (is.null(host)) host <- "localhost" # Default value
if (is.null(port)) port <- 7052 # Idem
cmd <- gsub("\n", "\\\\n", cmd)
cmd <- paste(cmd, collapse = " ")
@@ -31,7 +33,13 @@
rework(data[[n[i]]]), cmd)
}
}
-
+ # What type of data do we send?
+ cmd <- switch(type,
+ js = paste("<<<js>>>", cmd, sep = ""),
+ rjsonp = paste("<<<rjsonp>>>", pad, "(",
+ paste(toRjson(cmd, ...), collapse = " "), ")", sep = ""),
+ cmd)
+
otimeout <- getOption("timeout")
options(timeout = timeout) # Default timeout is 60 seconds
tryCatch(con <- socketConnection(host = host, port = port, blocking = TRUE),
Modified: pkg/svGUI/R/svGUI-internal.R
===================================================================
--- pkg/svGUI/R/svGUI-internal.R 2010-09-06 16:28:53 UTC (rev 288)
+++ pkg/svGUI/R/svGUI-internal.R 2010-09-06 16:29:37 UTC (rev 289)
@@ -1,19 +1,19 @@
".onLoad" <-
function (lib, pkg)
{
- serve <- getOption("ko.serve")
- if (!is.null(serve)) {
- startSocketServer(port = as.integer(serve)[1])
+ #serve <- getOption("ko.serve")
+ #if (!is.null(serve)) {
+ # startSocketServer(port = as.integer(serve)[1])
guiInstall()
- }
+ #}
}
".onUnload" <-
function (libpath)
{
- serve <- getOption("ko.serve")
- if (!is.null(serve) && "package:svSocket" %in% search())
- stopSocketServer(port = as.integer(serve)[1])
+ #serve <- getOption("ko.serve")
+ #if (!is.null(serve) && "package:svSocket" %in% search())
+ # stopSocketServer(port = as.integer(serve)[1])
guiUninstall()
}
Modified: pkg/svGUI/inst/CITATION
===================================================================
--- pkg/svGUI/inst/CITATION 2010-09-06 16:28:53 UTC (rev 288)
+++ pkg/svGUI/inst/CITATION 2010-09-06 16:29:37 UTC (rev 289)
@@ -3,7 +3,7 @@
citEntry(entry="Manual",
title = "SciViews-R: A GUI API for R",
author = "Philippe Grosjean",
- organization = "UMons",
+ organization = "UMONS",
address = "Mons, Belgium",
year = version$year,
url = "http://www.sciviews.org/SciViews-R",
@@ -11,7 +11,7 @@
textVersion =
paste("Grosjean, Ph. (", version$year, "). ",
"SciViews: A GUI API for R. ",
- "UMons, Mons, Belgium. ",
+ "UMONS, Mons, Belgium. ",
"URL http://www.sciviews.org/SciViews-R.",
sep="")
)
Added: pkg/svGUI/man/httpServer.Rd
===================================================================
--- pkg/svGUI/man/httpServer.Rd (rev 0)
+++ pkg/svGUI/man/httpServer.Rd 2010-09-06 16:29:37 UTC (rev 289)
@@ -0,0 +1,60 @@
+\name{startHttpServer}
+\alias{startHttpServer}
+\alias{stopHttpServer}
+\alias{HttpServerPort}
+\alias{HttpServerName}
+\alias{HttpClientsNames}
+\alias{parHttp}
+
+\title{ Use the R help HTTP server to serve SciViews-K/Komodo clients }
+
+\description{
+ These functions turn the default R help HTTP server into a RJSONp SciViews
+ server (while still serving help pages, of course) for GUI clients like
+ Komodo/SciViews-K.
+}
+
+\usage{
+startHttpServer(port = HttpServerPort(), name = HttpServerName())
+stopHttpServer(remove.clients = FALSE)
+
+HttpServerPort(port)
+HttpServerName(name)
+
+HttpClientsNames()
+parHttp(client, \dots)
+}
+
+\arguments{
+ \item{port}{ port on which the server should run (both help and SciViews).
+ By default, it is port 8888. Note that this server runs only locally and
+ can only serve requests from 127.0.0.1 }
+ \item{name}{ the name given to the SciViews server. By default, it is
+ \code{R} }
+ \item{remove.clients}{ Do we remove also persistent data for the clients,
+ \code{FALSE} by default }
+ \item{client}{ the name of one client. A client that does not identify itself
+ is named \code{default} }
+ \item{\dots}{ named arguments specifying options to set or change }
+}
+
+\value{
+ \code{startHttpServer()}, \code{stopHttpServer()} and \code{HttpServerPort()}
+ return an integer indicating the port used. For the last function, it is the
+ port that will be used if the HTTP server is not started yet.
+
+ The other functions return a character string or a list with the requested
+ information.
+}
+
+\note{
+ For \code{HttpServerPort()} and \code{HttpServerName()}, the argument is
+ optional. If it is specified, the corresponding option is changed, otherwise,
+ the function just returns the current value of the option.
+}
+
+\author{Philippe Grosjean (\email{phgrosjean at sciviews.org})}
+
+\seealso{ \code{\link[svSocket]{startSocketServer}} }
+
+\keyword{ IO }
Property changes on: pkg/svGUI/man/httpServer.Rd
___________________________________________________________________
Added: svn:executable
+ *
Modified: pkg/svGUI/man/koCmd.Rd
===================================================================
--- pkg/svGUI/man/koCmd.Rd 2010-09-06 16:28:53 UTC (rev 288)
+++ pkg/svGUI/man/koCmd.Rd 2010-09-06 16:29:37 UTC (rev 289)
@@ -12,7 +12,8 @@
\usage{
koCmd(cmd, data = NULL, async = FALSE, host = getOption("ko.host"),
- port = getOption("ko.port"), timeout = 1)
+ port = getOption("ko.port"), timeout = 1, type = c("js", "rjsonp", "output"),
+ pad = NULL, \dots)
}
\arguments{
@@ -29,6 +30,17 @@
default, it is port 7052. Can be changed by setting
\code{options(ko.port = ....)}. }
\item{timeout}{ Number of seconds to wait for response. }
+ \item{type}{ Which type of Komodo command do we send? If \code{type = "js"}
+ (by default), \code{cmd} is considered to be JavaScript code to be evaluated
+ in Komodo. If \code{type = "rjsonp"}, \code{cmd} is parsed as RJson object
+ with padding (included in a JavaScript function call) and will be evaluated
+ as such in Komodo. if \code{type = "output"}, the string in \code{cmd} is
+ considered to be some R output and will be displayed in the Komodo local
+ R console (no evaluation). }
+ \item{pad}{ A string naming the JavaScript function to run in Komodo, with
+ the constructed Rjson object as argument. If \code{NULL} (by default),
+ the Rjson object is evaluated directly without padding. }
+ \item{\dots}{ Further arguments to pass to \code{toRjson()}. }
}
\value{
@@ -80,6 +92,7 @@
# Make sure you have started Komodo Edit with the SciViews-K extension installed
# on the same machine you run R, and the socket server started and then...
+## Send JavaScript commands to Komodo
# Alert box in Komodo, and then reply to R
koCmd(c('alert("Hello from R!");',
'sv.socket.serverWrite("Hello from OpenKomodo (" + ko.interpolate.currentFilePath() + ")");'))
@@ -104,6 +117,16 @@
# Should return something like:
# "ReferenceError: nonexistingJSfunction is not defined"
+
+## Sending RjsonP (Rjson with padding) instruction to Komodo
+koCmd("Hello with RjsonP!", type = "rjsonp", pad = "alert")
+
+# This is more useful to pass complex R objects to Komodo
+koCmd(head(iris), type = "rjsonp", pad = "sv.socket.serverWrite")
+
+
+## Send simple text (no evaluation) to the Komodo R console
+koCmd("Hello again from R!", type = "output")
}
}
More information about the Sciviews-commits
mailing list