[Sciviews-commits] r190 - komodo/SciViews-K komodo/SciViews-K/content/js komodo/SciViews-K/pylib pkg/svGUI pkg/svGUI/R pkg/svGUI/man pkg/svSocket pkg/svSocket/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Sep 16 13:42:45 CEST 2009
Author: phgrosjean
Date: 2009-09-16 13:42:45 +0200 (Wed, 16 Sep 2009)
New Revision: 190
Added:
pkg/svGUI/R/guiRefresh.R
pkg/svGUI/man/guiRefresh.Rd
Modified:
komodo/SciViews-K/content/js/prefs.js
komodo/SciViews-K/content/js/r.js
komodo/SciViews-K/content/js/robjects.js
komodo/SciViews-K/pylib/lang_r.py
komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
pkg/svGUI/DESCRIPTION
pkg/svGUI/NAMESPACE
pkg/svGUI/NEWS
pkg/svGUI/R/guiInstall.R
pkg/svGUI/R/guiUninstall.R
pkg/svSocket/DESCRIPTION
pkg/svSocket/NEWS
pkg/svSocket/R/processSocket.R
Log:
Autorefresh of active object's lists and autorefresh of object explorer
Modified: komodo/SciViews-K/content/js/prefs.js
===================================================================
--- komodo/SciViews-K/content/js/prefs.js 2009-09-13 22:25:30 UTC (rev 189)
+++ komodo/SciViews-K/content/js/prefs.js 2009-09-16 11:42:45 UTC (rev 190)
@@ -106,9 +106,9 @@
// Set default dataset to 'df'
// Should be reset to a more useful value during first use of R
-sv.prefs.setString("r.active.data.frame", "df", false);
+sv.prefs.setString("r.active.data.frame", "df1", false);
+sv.prefs.setString("r.active.lm", "lm1", false);
-
//// (re)initialize a series of MRU for snippets' %ask constructs //////////////
// TODO: defaultMRU for ts, data, table, ...
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2009-09-13 22:25:30 UTC (rev 189)
+++ komodo/SciViews-K/content/js/r.js 2009-09-16 11:42:45 UTC (rev 190)
@@ -43,6 +43,9 @@
// sv.r.loadHistory(file, title); // Load the history from a file
// sv.r.saveGraph(type, file, title, height, width, method);
// // Save the current R graph in different formats
+// sv.r.obj(objClass); // Set active object for objClass (data.frame if omitted)
+// sv.r.obj_select(data); // The callback for sv.r.obj() to select an object
+// sv.r.obj_refresh_dataframe(data); // Refresh active data frame's MRUs
// sv.r.initSession(dir, datadir, scriptdir, reportdir);
// sv.r.setSession(dir, datadir, scriptdir, reportdir, saveOld, loadNew);
// Initialize R session with corresponding directories
@@ -353,6 +356,7 @@
}
}
var res = sv.r.eval(ke.selText);
+ ke.currentPos = ke.selectionEnd; // We want to go past the highest pos
ke.lineDown();
ke.homeDisplay();
} catch(e) {
@@ -361,7 +365,7 @@
return res;
}
-// Run current line up to position and optionally add line feed
+// Run current line (or selection) up to position and optionally add line feed
sv.r.runEnter = function (breakLine) {
try {
var res = false;
@@ -826,6 +830,139 @@
method + '")');
}
+// Select one object of class 'objClass' from .GlobalEnv
+sv.r.obj = function (objClass) {
+ // By default, we look at data.frames in .GlobalEnv
+ if (typeof(objClass) == "undefined") objClass = "data.frame";
+ var res = false;
+ // Get list of all objects with such a specification loaded in R
+ // If there is a comment attribute, also get it
+ res = sv.r.evalCallback('cat("' + objClass + '\n");' +
+ 'cat(unlist(apply(matrix(objects(pos = 1)), 1, ' +
+ 'function(x) try(if (inherits(get(x), "' + objClass +
+ '")) paste(x, "\t ", sub("[\t\n\r].*$", "", ' +
+ 'comment(get(x))), sep = ""), silent = TRUE))), sep = ",,,")',
+ sv.r.obj_select);
+ ko.statusBar.AddMessage("Listing available '" + objClass +
+ "'... please wait", "R", 20000, true);
+ return(res);
+}
+
+// The callback for sv.r.obj
+sv.r.obj_select = function (data) {
+ ko.statusBar.AddMessage("", "R");
+ var res = false;
+ if (sv.tools.strings.removeLastCRLF(data) == "") {
+ sv.alert("Select R objects", "Problem retrieving the list of objects!");
+ } else { // Something is returned
+ var res = data.split("\n");
+ // First item is objClass, second one is the list of objects
+ var objclass = sv.tools.strings.removeLastCRLF(res[0]);
+ if (typeof(res[1]) == "undefined") {
+ sv.alert("Select R objects", "No object of class '" + objclass +
+ "' currently loaded in R memory!");
+ } else { // At least one object, display a selection list
+ var items = res[1].split(",,,");
+ // TODO: highlight current active object...
+ // Select the item you want in the list
+ var item = ko.dialogs.selectFromList("Currently loaded '" +
+ objclass + "' objects in R",
+ "Select one '" + objclass + "' to make it active in Komodo:",
+ items, "one");
+ if (item != null) {
+ // Update default object
+ // We need to eliminate the comment first
+ var obj = item[0].split("\t");
+ var objname = obj[0];
+ // The rest of the treatment depends on objClass
+ if (objclass == "data.frame") {
+ // Refresh the default val and list of vars
+ res = sv.r.evalCallback(
+ '.active.data.frame <- list(object = "' + objname +
+ '", fun = function () {\n' +
+' if (exists(.active.data.frame$object, envir = .GlobalEnv)) {\n' +
+' obj <- get(.active.data.frame$object, envir = .GlobalEnv)\n' +
+' res <- paste(c(.active.data.frame$object, names(obj)), "\t",\n' +
+' c(class(obj), sapply(obj, class)), "\n", sep = "")\n' +
+' return(.active.data.frame$cache <<- res)\n' +
+' } else return(.active.data.frame$cache <<- NULL)\n' +
+ '}, cache = "")\n' +
+ 'cat(.active.data.frame$fun(), sep = "")',
+ sv.r.obj_refresh_dataframe);
+ } else {
+ // Not implemented yet for other objects!
+ //alert("Update of MRU lists not implemented yet for other " +
+ // "objects than 'data.frame'");
+ // Temporary code: at least set pref value
+ sv.prefs.setString("r.active." + objclass, objname, true);
+ }
+ }
+ }
+ }
+ return(res);
+}
+
+// Callback for sv.r.obj_select to refresh the MRUs associated with data frames
+sv.r.obj_refresh_dataframe = function (data) {
+ ko.statusBar.AddMessage("", "R");
+ // If we got nothing, then the object does not exists any more... clear MRUs
+ if (data == "<<<data>>>") {
+ var oldobj = sv.prefs.getString("r.active.data.frame", "");
+ sv.prefs.setString("r.active.data.frame", "df1", true); // Default value
+ sv.prefs.mru("var", true, "", "|");
+ sv.prefs.mru("var2", true, "", "|");
+ sv.prefs.mru("x", true, "", "|");
+ sv.prefs.mru("x2", true, "", "|");
+ sv.prefs.mru("y", true, "", "|");
+ sv.prefs.mru("factor", true, "", "|");
+ sv.prefs.mru("factor2", true, "", "|");
+ sv.prefs.mru("blockFactor", true, "", "|");
+ // Display a message
+ ko.statusBar.AddMessage("Active data frame '" + oldobj + "' removed",
+ "R", 10000, true);
+ return(false);
+ }
+
+ var items = data.split("\n");
+ // First item contains the name of the active object and its class
+ var item = sv.tools.strings.removeLastCRLF(items[0]).split("\t");
+ var objname = item[0];
+ var objclass = item[1];
+ // Make sure r.active.data.frame pref is set to obj
+ sv.prefs.setString("r.active." + objclass, objname, true);
+ items.shift(); // Eliminate first item from the array
+ // Create three lists: vars collects all var names, nums and facts do so for
+ // only numeric and factor variables (separate items by "|")
+ var vars = "", nums = "", facts = "";
+ for (i in items) {
+ item = sv.tools.strings.removeLastCRLF(items[i]).split("\t");
+ // Fill the various lists according to the nature of item
+ vars = vars + "|" + item[0];
+ if (item[1] == "numeric") nums = nums + "|" + item[0];
+ if (item[1] == "factor") facts = facts + "|" + item[0];
+ }
+ // Eliminate first "|"
+ vars = vars.substr(1);
+ nums = nums.substr(1);
+ facts = facts.substr(1);
+ // Add these lists in various MRUs
+ // vars => var and var2
+ sv.prefs.mru("var", true, vars, "|");
+ sv.prefs.mru("var2", true, vars, "|");
+ // nums => x, x2, y
+ sv.prefs.mru("x", true, nums, "|");
+ sv.prefs.mru("x2", true, nums, "|");
+ sv.prefs.mru("y", true, nums, "|");
+ // facts => factor, factor2, blockFactor
+ sv.prefs.mru("factor", true, facts, "|");
+ sv.prefs.mru("factor2", true, facts, "|");
+ sv.prefs.mru("blockFactor", true, facts, "|");
+ // Report which object is currently active (TODO: indicate this in obj explorer)
+ ko.statusBar.AddMessage("Active " + objclass +
+ ": " + objname, "R", 20000, true);
+ return(true);
+}
+
// Initialize R session preferences in Komodo
// use sv.r.setSession() except at startup!
sv.r.initSession = function (dir, datadir, scriptdir, reportdir) {
Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js 2009-09-13 22:25:30 UTC (rev 189)
+++ komodo/SciViews-K/content/js/robjects.js 2009-09-16 11:42:45 UTC (rev 190)
@@ -71,7 +71,8 @@
// getSelectedRows
// toString - textual representation of the tree for debugging purposes
// init - initialize
-// refreshAll
+// refreshAll()
+// refreshGlobalEnv(data); // R sends data to refresh the global environment
// removeSelected
// getSelectedNames
// insertName
@@ -1015,6 +1016,10 @@
sv.r.evalCallback(cmd, _parseObjectList);
}
+ this.refreshGlobalEnv = function (data) {
+ this._parseObjectList(data);
+ }
+
//TODO: on package deletion -> remove it also from the search path
this.removeSelected = function (doRemove) {
var item, type, name, vItem, cmd = [];
Modified: komodo/SciViews-K/pylib/lang_r.py
===================================================================
--- komodo/SciViews-K/pylib/lang_r.py 2009-09-13 22:25:30 UTC (rev 189)
+++ komodo/SciViews-K/pylib/lang_r.py 2009-09-16 11:42:45 UTC (rev 190)
@@ -2977,7 +2977,7 @@
cb_show_if_empty = True
- cpln_fillup_chars = "~`!$@#%^&*()-=+{}[]|\\;:'\",<>?/\t\n\r"
+ cpln_fillup_chars = "\t" #"~`!$@#%^&*()-=+{}[]|\\;:'\",<>?/\t\n\r"
cpln_stop_chars = "~`!$@#%^&*()-=+{}[]|\\;:'\",<>?/ "
# Dev Note: many details elided.
Modified: komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
===================================================================
(Binary files differ)
Modified: pkg/svGUI/DESCRIPTION
===================================================================
--- pkg/svGUI/DESCRIPTION 2009-09-13 22:25:30 UTC (rev 189)
+++ pkg/svGUI/DESCRIPTION 2009-09-16 11:42:45 UTC (rev 190)
@@ -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-44
-Date: 2009-01-22
+Version: 0.9-45
+Date: 2009-09-16
Author: Philippe Grosjean
Maintainer: Philippe Grosjean <phgrosjean at sciviews.org>
License: GPL (>= 2)
Modified: pkg/svGUI/NAMESPACE
===================================================================
--- pkg/svGUI/NAMESPACE 2009-09-13 22:25:30 UTC (rev 189)
+++ pkg/svGUI/NAMESPACE 2009-09-16 11:42:45 UTC (rev 190)
@@ -2,4 +2,6 @@
export(guiInstall,
guiUninstall,
+ guiRefresh,
+ guiAutoRefresh,
koCmd)
Modified: pkg/svGUI/NEWS
===================================================================
--- pkg/svGUI/NEWS 2009-09-13 22:25:30 UTC (rev 189)
+++ pkg/svGUI/NEWS 2009-09-16 11:42:45 UTC (rev 190)
@@ -1,5 +1,11 @@
= svGUI News
+== Changes in svGUI 0.9-45
+
+* Added guiRefresh() and guiAutoRefresh() to refresh automatically the content
+of the GUI (Komodo) object explorer and the lists of active objects
+
+
== Changes in svGUI 0.9-44
* Preparation for CRAN submission: polishing the package
Modified: pkg/svGUI/R/guiInstall.R
===================================================================
--- pkg/svGUI/R/guiInstall.R 2009-09-13 22:25:30 UTC (rev 189)
+++ pkg/svGUI/R/guiInstall.R 2009-09-16 11:42:45 UTC (rev 190)
@@ -35,14 +35,15 @@
# Register a TaskCallback to generate automatically informations for an object browser
# Use getTaskCallbackNames() to know if some tasks are registered
- assignTemp(".guiObjCallback", function(...) {
- ob <- names(getTemp(".guiObjListCache", default = NULL))
- if (!is.null(ob)) for (i in 1:length(ob)) objBrowse(id = ob[i])
- return(TRUE) # Required to keep it in the TaskCallback list
- })
+# assignTemp(".guiObjCallback", function(...) {
+# ob <- names(getTemp(".guiObjListCache", default = NULL))
+# if (!is.null(ob)) for (i in 1:length(ob)) objBrowse(id = ob[i])
+# return(TRUE) # Required to keep it in the TaskCallback list
+# })
Callback <- getTemp(".guiObjCallbackId", default = NULL)
if (is.null(Callback)) {
- n <- addTaskCallback(getTemp(".guiObjCallback"))
+# n <- addTaskCallback(getTemp(".guiObjCallback"))
+ n <- addTaskCallback(guiAutoRefresh)
if (!is.null(n)) assignTemp(".guiObjCallbackId", as.character(n))
}
}
Added: pkg/svGUI/R/guiRefresh.R
===================================================================
--- pkg/svGUI/R/guiRefresh.R (rev 0)
+++ pkg/svGUI/R/guiRefresh.R 2009-09-16 11:42:45 UTC (rev 190)
@@ -0,0 +1,44 @@
+.active.data.frame <- list(object = "",
+ fun = function () {
+ if (exists(.active.data.frame$object, envir = .GlobalEnv)) {
+ obj <- get(.active.data.frame$object, envir = .GlobalEnv)
+ res <- paste(names(obj), "\t", sapply(obj, class), "\n", sep = "")
+ return(.active.data.frame$cache <<- res)
+ } else return(.active.data.frame$cache <<- NULL)
+ }, cache = "")
+
+
+guiRefresh <- function (force = FALSE) {
+ # Refresh active items and the R Objects explorer
+ # If force == TRUE, do not compare with the cache
+ # Active items are represented by .active.xxx objects in .GlobalEnv
+ aObjs <- ls(pattern = "^\\.active\\.", envir = .GlobalEnv, all.names = TRUE)
+ for (item in aObjs) {
+ obj <- get(item, envir = .GlobalEnv, inherits = FALSE)
+ if (mode(obj) == "list") {
+ objclass <- sub("^\\.active\\.", "", item)
+ # JavaScript does not accept dots in function names. So, we have
+ # to remove them from class name (eg., data.frame => dataframe)
+ objclass <- gsub("\\.", "", objclass)
+ cache <- obj$cache
+ res <- obj$fun()
+ if (is.null(res)) # Active object not found, remove obj
+ rm(list = item, envir = .GlobalEnv)
+ if (isTRUE(force) || !identical(res, cache)) # Refresh in Komodo
+ koCmd(paste('sv.r.obj_refresh_', objclass, '("<<<data>>>");',
+ sep = ""), data = res)
+ }
+ }
+ # Refresh object browser (only data from .GlobalEnv)
+ lst <- objList(envir = .GlobalEnv, all.info = FALSE, compare = TRUE)
+ if (length(lst$Name) > 0)
+ koCmd('sv.r.objects.refreshGlobalEnv("<<<data>>>");',
+ data = print(lst, sep = ";;", raw.output = TRUE, header = TRUE))
+
+ return(TRUE)
+}
+
+guiAutoRefresh <- function (...) {
+ guiRefresh(force = FALSE)
+ return(TRUE)
+}
\ No newline at end of file
Modified: pkg/svGUI/R/guiUninstall.R
===================================================================
--- pkg/svGUI/R/guiUninstall.R 2009-09-13 22:25:30 UTC (rev 189)
+++ pkg/svGUI/R/guiUninstall.R 2009-09-16 11:42:45 UTC (rev 190)
@@ -13,6 +13,7 @@
# Use getTaskCallbackNames() to know if some tasks are registered
Callback.Id <- getTemp(".guiObjCallbackId", default = NULL)
if (!is.null(Callback.Id)) {
- if (removeTaskCallback(Callback.Id)) assignTemp(".guiObjCallbackId", NULL)
+ if (removeTaskCallback(Callback.Id))
+ assignTemp(".guiObjCallbackId", NULL)
}
}
Added: pkg/svGUI/man/guiRefresh.Rd
===================================================================
--- pkg/svGUI/man/guiRefresh.Rd (rev 0)
+++ pkg/svGUI/man/guiRefresh.Rd 2009-09-16 11:42:45 UTC (rev 190)
@@ -0,0 +1,29 @@
+\name{guiRefresh}
+\alias{guiRefresh}
+\alias{guiAutoRefresh}
+
+\title{ Refresh GUI (Komodo) elements, like active object lists and object browser }
+\description{
+ These function manage to refresh the list of active objects in Komodo and also
+ the data displayed in the Komodo R object browser. They should not be called
+ directly by the end-user.
+}
+\usage{
+guiRefresh(force = FALSE)
+guiAutoRefresh(...)
+}
+
+\arguments{
+ \item{force}{ Do we force refresh, even if data have not changed? }
+ \item{...}{ Any argument (ignored, but useful for \code{addTaskCallback()}) }
+}
+
+\value{
+ Both functions return \code{TRUE} on success.
+}
+
+\author{Philippe Grosjean (\email{phgrosjean at sciviews.org})}
+
+\seealso{ \code{\link{koCmd}} }
+
+\keyword{misc}
Modified: pkg/svSocket/DESCRIPTION
===================================================================
--- pkg/svSocket/DESCRIPTION 2009-09-13 22:25:30 UTC (rev 189)
+++ pkg/svSocket/DESCRIPTION 2009-09-16 11:42:45 UTC (rev 190)
@@ -4,8 +4,8 @@
Depends: R (>= 2.6.0)
Imports: tcltk, svMisc
Description: Implements a simple socket server allowing to connect GUI clients to R
-Version: 0.9-46
-Date: 2009-08-10
+Version: 0.9-47
+Date: 2009-09-16
Author: Philippe Grosjean, Matthew Dowle
Maintainer: Philippe Grosjean <phgrosjean at sciviews.org>
License: GPL (>= 2)
Modified: pkg/svSocket/NEWS
===================================================================
--- pkg/svSocket/NEWS 2009-09-13 22:25:30 UTC (rev 189)
+++ pkg/svSocket/NEWS 2009-09-16 11:42:45 UTC (rev 190)
@@ -1,5 +1,10 @@
= svSocket News
+== Changes in svSocket 0.9-47
+
+* The server now calls taskCallbacks on non-hidden mode after code evaluation
+
+
== Changes in svSocket 0.9-46
* evalServer() slightly reworked
Modified: pkg/svSocket/R/processSocket.R
===================================================================
--- pkg/svSocket/R/processSocket.R 2009-09-13 22:25:30 UTC (rev 189)
+++ pkg/svSocket/R/processSocket.R 2009-09-16 11:42:45 UTC (rev 190)
@@ -124,6 +124,9 @@
if (length(expr) < 1) return(paste(pars$last, Prompt, sep = ""))
# Correct code,... we evaluate it
results <- captureAll(expr)
+ # Should we run taskCallbacks?
+ if (!hiddenMode)
+ results <- c(results, taskCallbackManager()$evaluate())
# Collapse and add last and the prompt at the end
results <- paste(results, collapse = "\n")
if (Echo) cat(results)
More information about the Sciviews-commits
mailing list