[Sciviews-commits] r8 - in pkg: svIDE svIDE/R svIDE/man svMisc svMisc/R svSocket/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jun 9 23:51:44 CEST 2008
Author: phgrosjean
Date: 2008-06-09 23:51:43 +0200 (Mon, 09 Jun 2008)
New Revision: 8
Modified:
pkg/svIDE/DESCRIPTION
pkg/svIDE/NEWS
pkg/svIDE/R/createCallTipFile.R
pkg/svIDE/R/getFunctions.R
pkg/svIDE/R/guiDDEInstall.R
pkg/svIDE/man/guiDDEInstall.Rd
pkg/svMisc/NEWS
pkg/svMisc/R/Args.R
pkg/svSocket/R/startSocketServer.R
Log:
Bug fixes in the DDE server in svIDE and little enhancement in svMisc
Modified: pkg/svIDE/DESCRIPTION
===================================================================
--- pkg/svIDE/DESCRIPTION 2008-06-08 18:46:14 UTC (rev 7)
+++ pkg/svIDE/DESCRIPTION 2008-06-09 21:51:43 UTC (rev 8)
@@ -3,8 +3,8 @@
Imports: utils
Depends: R (>= 2.7.0), tcltk, svMisc
Description: Function for the GUI API to interact with external IDE/code editors
-Version: 0.9-41
-Date: 2008-06-06
+Version: 0.9-42
+Date: 2008-06-09
Author: Philippe Grosjean
Maintainer: Philippe Grosjean <phgrosjean at sciviews.org>
License: GPL (>= 2)
Modified: pkg/svIDE/NEWS
===================================================================
--- pkg/svIDE/NEWS 2008-06-08 18:46:14 UTC (rev 7)
+++ pkg/svIDE/NEWS 2008-06-09 21:51:43 UTC (rev 8)
@@ -1,5 +1,17 @@
= svIDE News
+== Changes in svIDE 0.9-42
+* getKeywords() is simplified by using lsf.str().
+
+* guiDDEInstall now uses .Tcl.args() instead of .Tcl.callback to install
+ callback functions in Tcl (preventing for moving the function in another
+ memory location)
+
+* A change in argument names for guiCalltip() and guiComplete() prevented the
+ DDE server to work properly for those two commands (Tinn-R). This bug is
+ fixed (Tcl does not support names with dots, like max.width). Hence, the
+ argument is changed to maxWidth. Same for only.args that becomes onlyArgs.
+
== Changes in svIDE 0.9-41
* One bug corrected in trObjSearch(): incorrect output of the results in a
character vector.
Modified: pkg/svIDE/R/createCallTipFile.R
===================================================================
--- pkg/svIDE/R/createCallTipFile.R 2008-06-08 18:46:14 UTC (rev 7)
+++ pkg/svIDE/R/createCallTipFile.R 2008-06-09 21:51:43 UTC (rev 8)
@@ -2,24 +2,22 @@
function(file = "Rcalltips.txt", pos = 2:length(search()), field.sep = "=",
only.args = FALSE, return.location = FALSE) {
# Create a .txt file containing calltips for R functions.
-
- # Create the beginning of the file
- cat("", file = file) # Currently, needs nothing...
-
+ cat("", file = file) # Create the beginning of the file
+
# Get the list of keywords
keys <- getKeywords(pos = pos)
-
+
# For each keyword, write a line in the file with keyword=calltip
- for (i in 1:length(keys)) {
- ctip <- CallTip(keys[i], only.args = only.args)
+ for (key in keys) {
+ ctip <- CallTip(key, only.args = only.args)
if (ctip != "") {
if (return.location == TRUE) {
# Get the package from where it is located and append it
- pkg <- sub("^package:", "", find(keys[i], mode = "function"))
+ pkg <- sub("^package:", "", find(key, mode = "function"))
if (length(pkg) > 0 && pkg != ".GlobalEnv")
pkg <- paste(" [", pkg, "]", sep = "") else pkg <- " []"
} else pkg <- ""
- cat(keys[i], field.sep, ctip, pkg, "\n", sep = "", file = file,
+ cat(key, field.sep, ctip, pkg, "\n", sep = "", file = file,
append = TRUE)
}
}
Modified: pkg/svIDE/R/getFunctions.R
===================================================================
--- pkg/svIDE/R/getFunctions.R 2008-06-08 18:46:14 UTC (rev 7)
+++ pkg/svIDE/R/getFunctions.R 2008-06-09 21:51:43 UTC (rev 8)
@@ -1,15 +1,5 @@
"getFunctions" <-
function(pos) {
# Get a list of all R functions in a certain position
- lst <- objects(pos = pos, all.names = TRUE)
- l <- length(lst)
- if (l == 0) return(NULL) else {
- isFun <- rep(FALSE, l)
- for (i in 1:l)
- if (exists(lst[i], where = pos, mode = "function", inherits = FALSE))
- isFun[i] <- TRUE
- # Keep only functions
- lst <- lst[isFun]
- return(lst)
- }
+ return(as.character(lsf.str(pos = pos, all.names = TRUE)))
}
Modified: pkg/svIDE/R/guiDDEInstall.R
===================================================================
--- pkg/svIDE/R/guiDDEInstall.R 2008-06-08 18:46:14 UTC (rev 7)
+++ pkg/svIDE/R/guiDDEInstall.R 2008-06-09 21:51:43 UTC (rev 8)
@@ -1,21 +1,21 @@
"guiCallTip" <-
-function(code, file = NULL, only.args = FALSE, max.width = 60, location = FALSE) {
+function(code, file = NULL, onlyArgs = FALSE, maxWidth = 60, location = FALSE) {
# This is an interface to CallTip for external programs
# Clear ::SciViewsR_CallTip
.Tcl("set ::SciViewsR_CallTip {}")
# Using a callback, all args are strings => convert
if (length(file) == 0 || file == "" || file == "NULL") file <- NULL
- only.args <- as.logical(only.args[1])
- max.width <- as.integer(max.width[1])
-
+ onlyArgs <- as.logical(onlyArgs[1])
+ maxWidth <- as.integer(maxWidth[1])
+
# Get the call tip
- ctip <- CallTip(code, only.args = only.args, location = location)
+ ctip <- CallTip(code, only.args = onlyArgs, location = location)
# Possibly break long lines at reasonables widths
- if (only.args) Exdent <- 0 else Exdent <- 4
- if (!is.null(max.width) && !max.width < 1)
- ctip <- paste(strwrap(ctip, width = max.width, exdent = Exdent), collapse = "\n")
+ if (onlyArgs) Exdent <- 0 else Exdent <- 4
+ if (!is.null(maxWidth) && !maxWidth < 1)
+ ctip <- paste(strwrap(ctip, width = maxWidth, exdent = Exdent), collapse = "\n")
# Copy the result to a Tcl variable
.Tcl(paste("set ::SciViewsR_CallTip {", ctip, "}", sep = ""))
@@ -40,7 +40,7 @@
# This is an interfacte to Complete for external programs
# Clear ::SciViewsR_Complete
.Tcl("set ::SciViewsR_Complete {}")
-
+
# Using a callback, all args are strings => convert
if (length(file) == 0 || file == "" || file == "NULL") file <- NULL
givetype <- as.logical(givetype[1])
@@ -102,16 +102,15 @@
# Install callbacks for guiXXXX functions, for DDE clients to access them
# guiCallTip()... Take care: must be adapted if you change guiCallTip()!
- res <- .Tcl.callback(guiCallTip)
- .Tcl(paste("proc guiCallTip {code {file \"\"} {onlyargs FALSE}",
- " {maxwidth 60} {location FALSE} } {", gsub("%", "$", res), "}",
- sep = ""))
-
+ res <- .Tcl.args(guiCallTip)
+ .Tcl(paste("proc guiCallTip {code {file \"\"} {onlyArgs FALSE}",
+ " {maxWidth 60} {location FALSE} }", gsub("%", "$", res), sep = ""))
+
# guiComplete()... Take care: must be adapted if you change guiComplete()!
- res <- .Tcl.callback(guiComplete)
+ res <- .Tcl.args(guiComplete)
.Tcl(paste("proc guiComplete {code {file \"\"} {givetype FALSE}",
- " {fieldsep |} } {", gsub("%", "$", res), "}", sep = ""))
-
+ " {sep |} }", gsub("%", "$", res), sep = ""))
+
# Done
return(invisible("")) # OK!
}
Modified: pkg/svIDE/man/guiDDEInstall.Rd
===================================================================
--- pkg/svIDE/man/guiDDEInstall.Rd 2008-06-08 18:46:14 UTC (rev 7)
+++ pkg/svIDE/man/guiDDEInstall.Rd 2008-06-09 21:51:43 UTC (rev 8)
@@ -10,7 +10,7 @@
}
\usage{
guiDDEInstall()
-guiCallTip(code, file = NULL, only.args = FALSE, max.width = 60, location = FALSE)
+guiCallTip(code, file = NULL, onlyArgs = FALSE, maxWidth = 60, location = FALSE)
guiComplete(code, file = NULL, givetype = FALSE, sep = "|")
}
@@ -18,8 +18,8 @@
\item{code}{ A piece of R code (in a character string) to analyze }
\item{file}{ A file where to return the result ("", or NULL for none). You
can use "clipboard" to send the result to the clipboard under Windows only }
- \item{only.args}{ Do we return the whole calltip or only the function arguments? }
- \item{max.width}{ Reformat the calltip to max.with (use 0 for not reformatting it) }
+ \item{onlyArgs}{ Do we return the whole calltip or only the function arguments? }
+ \item{maxWidth}{ Reformat the calltip to max.with (use 0 for not reformatting it) }
\item{location} { If \code{TRUE} then the location (in which package the
function resides) is appended to the calltip between square brackets }
\item{givetype}{ Return also the type of each object in the completion list (possibly
@@ -54,7 +54,7 @@
options(use.DDE = TRUE)
library(svIDE) # This should automatically start the
# DDE server named 'TclEval SciViewsR', according to the option set
-
+
# Get some data in the user workspace
data(trees)
a <- 1
@@ -68,7 +68,7 @@
.Tcl("dde services TclEval {}")
# You should get 'TclEval SciViewsR' in the list
# if the server in the first instance is running
-
+
# Now, request a calltip for the function 'ls'
# This is done in two steps:
# 1) Execute the command 'guiCallTip' with this code chunk as argument
@@ -98,5 +98,3 @@
}
}
\keyword{ utilities }
-
-
Modified: pkg/svMisc/NEWS
===================================================================
--- pkg/svMisc/NEWS 2008-06-08 18:46:14 UTC (rev 7)
+++ pkg/svMisc/NEWS 2008-06-09 21:51:43 UTC (rev 8)
@@ -6,7 +6,10 @@
* objXXX() functions did not always returned results invisibly. Solved.
+* Args() is more robust against bad 'name' parameter because it now calls
+ argsAnywhere() within a try().
+
== Changes in svMisc 0.9-41
* objInfo() returns also estimated size of objects that are not functions.
Modified: pkg/svMisc/R/Args.R
===================================================================
--- pkg/svMisc/R/Args.R 2008-06-08 18:46:14 UTC (rev 7)
+++ pkg/svMisc/R/Args.R 2008-06-09 21:51:43 UTC (rev 8)
@@ -1,8 +1,10 @@
"Args" <-
function(name, only.args = FALSE){
#### TODO: handle primitives and S3/S4 methods for generic functions
- res <- eval(parse(text = paste("argsAnywhere(", name, ")", sep = "")))
- if (is.null(res)) return("") # Function 'name' not found
+ ret <- try(res <- eval(parse(text = paste("argsAnywhere(", name, ")",
+ sep = ""))), silent = TRUE)
+ if (inherits(ret, "try-error") || is.null(res))
+ return("") # Function 'name' not found
res <- deparse(res)
res <- paste(res[-length(res)], collapse = "\n")
if (only.args) {
Modified: pkg/svSocket/R/startSocketServer.R
===================================================================
--- pkg/svSocket/R/startSocketServer.R 2008-06-08 18:46:14 UTC (rev 7)
+++ pkg/svSocket/R/startSocketServer.R 2008-06-09 21:51:43 UTC (rev 8)
@@ -112,7 +112,7 @@
return(TRUE) # The command is processed
}
# This is a copy of tclFun from tcltk2, to avoid a Depends: tcltk2
- "tclFun_" <- function (f, name = deparse(substitute(f)), envir = TempEnv()) {
+ "tclFun_" <- function (f, name = deparse(substitute(f))) {
# Register a simple R function (no arguments) as a callback in Tcl,
# and give it the same name)
# Indeed, .Tcl.callback(f) in tcltk package does the job...
@@ -129,11 +129,11 @@
stop("'name' must be a character string!") else
name <- make.names(name[1])
- res <- .Tcl.callback(f, envir)
+ res <- .Tcl.args(f)
# Make sure this is correct (R_call XXXXXXXX)
if (length(grep("R_call ", res) > 0)) {
# Create a proc with the same name in Tcl
- .Tcl(paste("proc ", name, " {} {", res, "}", sep = ""))
+ .Tcl(paste("proc ", name, " {}", res, sep = ""))
}
# Return the R_call XXXXXXXX string, as .Tcl.callback() does
return(res)
More information about the Sciviews-commits
mailing list