[Sciviews-commits] r257 - in pkg: . svGUI svGUI/R svGUI/man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Apr 30 00:59:57 CEST 2010
Author: prezez
Date: 2010-04-30 00:59:57 +0200 (Fri, 30 Apr 2010)
New Revision: 257
Modified:
pkg/
pkg/svGUI/
pkg/svGUI/DESCRIPTION
pkg/svGUI/R/koCmd.R
pkg/svGUI/man/koCmd.Rd
Log:
koCmd: timeout attribute added with a default of 1 second.(previously was 60 sec. which caused problems when Komodo was not available).
Property changes on: pkg
___________________________________________________________________
Added: svn:ignore
+ !*
*-dev.*
Property changes on: pkg/svGUI
___________________________________________________________________
Added: svn:ignore
+ !*
*-dev.*
Modified: pkg/svGUI/DESCRIPTION
===================================================================
--- pkg/svGUI/DESCRIPTION 2010-04-22 19:39:33 UTC (rev 256)
+++ pkg/svGUI/DESCRIPTION 2010-04-29 22:59:57 UTC (rev 257)
@@ -6,8 +6,8 @@
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-46
-Date: 2009-09-17
+Version: 0.9-47
+Date: 2010-04-29
Author: Philippe Grosjean
Maintainer: Philippe Grosjean <phgrosjean at sciviews.org>
License: GPL (>= 2)
Modified: pkg/svGUI/R/koCmd.R
===================================================================
--- pkg/svGUI/R/koCmd.R 2010-04-22 19:39:33 UTC (rev 256)
+++ pkg/svGUI/R/koCmd.R 2010-04-29 22:59:57 UTC (rev 257)
@@ -1,7 +1,8 @@
"koCmd" <-
function (cmd, data = NULL, async = FALSE, host = getOption("ko.host"),
- port = getOption("ko.port"))
+ port = getOption("ko.port"), timeout = 1)
{
+
if (is.null(host)) host <- "localhost" # Default value
if (is.null(port)) port <- 7052 # Idem
cmd <- gsub("\n", "\\\\n", cmd)
@@ -30,32 +31,16 @@
rework(data[[n[i]]]), cmd)
}
}
- owarn <- getOption("warn")
- options(warn = -1) # Eliminate warnings (in case the Komodo server is not available)
- ret <- try(con <- socketConnection(host = host, port = port, blocking = TRUE),
- silent = TRUE)
- options(warn = owarn) # Restore warnings
- if (inherits(ret, "try-error")) {
- data <- "Komodo socket server is not available!"
- class(data) <- "try-error"
- return(data)
- }
+
+ otimeout <- getOption("timeout")
+ options(timeout = timeout) # Default timeout is 60 seconds
+ tryCatch(con <- socketConnection(host = host, port = port, blocking = TRUE),
+ warning = function(e) {
+ stop(simpleError("Komodo socket server is not available!", quote(koCmd)))
+ })
writeLines(cmd, con)
res <- readLines(con)
close(con)
- # Did Komodo returned an error?
- getError <- function(data) {
- if (length(data) == 2 && data[1] == "" &&
- substring(data[2], 0, 6) == "Error:") {
- Err <- substring(data[2], 8)
- # One can also add clear messages for other errors
- data <- switch(Err,
- "2147500037" = "Error: incorrect JavaScript code",
- paste("Error: an unknown error", Err, "was returned by Komodo")
- )
- class(data) <- "try-error"
- }
- return(data)
- }
- return(getError(res))
+ options(timeout = otimeout)
+ return(res)
}
Modified: pkg/svGUI/man/koCmd.Rd
===================================================================
--- pkg/svGUI/man/koCmd.Rd 2010-04-22 19:39:33 UTC (rev 256)
+++ pkg/svGUI/man/koCmd.Rd 2010-04-29 22:59:57 UTC (rev 257)
@@ -12,7 +12,7 @@
\usage{
koCmd(cmd, data = NULL, async = FALSE, host = getOption("ko.host"),
- port = getOption("ko.port"))
+ port = getOption("ko.port"), timeout = 1)
}
\arguments{
@@ -28,14 +28,16 @@
\item{port}{ The socket port where the SciViews-K server is listening, by
default, it is port 7052. Can be changed by setting
\code{options(ko.port = ....)}. }
+ \item{timeout}{ Number of seconds to wait for response. }
}
\value{
Returns the results of the evaluation of the javascript code in Komodo Edit if
\code{async = FALSE}. Note that \code{async = TRUE} is not supported yet.
- If there is an error, or \code{cmd} is an invalid javascript code, an error
- is returned with the class \'try-error\' (see last example).
+ If there is an error, or \code{cmd} is an invalid javascript code,
+ a character string containing javascript error message is returned.
+ (Note: this changed from version 0.9-47, previously a 'try-error' was returned)
}
\details{
@@ -98,9 +100,10 @@
koCmd('alert("This is R version <<<major>>>.<<<minor>>>");', R.version)
# Sending incorrect javascript instruction
-res <- koCmd('nonexistingJSfunction();')
-res
-if (inherits(res, "try-error")) cat("Error detected!")
+ koCmd('nonexistingJSfunction();')
+# Should return something like:
+# "ReferenceError: nonexistingJSfunction is not defined"
+
}
}
More information about the Sciviews-commits
mailing list