[Sciviews-commits] r332 - in komodo/SciViews-K: content/js defaults

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 13 18:09:45 CEST 2010


Author: prezez
Date: 2010-10-13 18:09:45 +0200 (Wed, 13 Oct 2010)
New Revision: 332

Modified:
   komodo/SciViews-K/content/js/pref-R.js
   komodo/SciViews-K/content/js/r.js
   komodo/SciViews-K/content/js/robjects.js
   komodo/SciViews-K/defaults/svStart.R
Log:
Preferences panel: handling of custom arguments in R command line (--args ...)
sv.r.saveDataFrame: fixed
sv.r.objects: small improvements to context menu.
svStart.R: automatic detection of minVersion of packages.
svMisc::objList: bug fixed (base environment was listed as .GlobalEnv)

Modified: komodo/SciViews-K/content/js/pref-R.js
===================================================================
--- komodo/SciViews-K/content/js/pref-R.js	2010-10-05 11:20:43 UTC (rev 331)
+++ komodo/SciViews-K/content/js/pref-R.js	2010-10-13 16:09:45 UTC (rev 332)
@@ -312,12 +312,26 @@
     var appId = document.getElementById("svRApplication").value;
     var appPath = document.getElementById("svRDefaultInterpreter").value;
     var cmdArgs = document.getElementById("svRArgs").value;
-    var args1 = document.getElementById("sciviews.pkgs.sciviews").checked ?
-    " --args --pkgs=SciViews,MASS,ellipse" : "";
+	var args1 = "";
 
+	if(document.getElementById("sciviews.pkgs.sciviews").checked)
+			args1 += " --svStartPkgs=SciViews,MASS,ellipse";
+
    	var cwd = sv.tools.file.path("ProfD", "extensions",
     "sciviewsk at sciviews.org", "defaults");
 
+	cmdArgs = cmdArgs.replace(/\s*--mdi/, "");
+
+	var argsPos = cmdArgs.indexOf("--args");
+	if(argsPos != -1) {
+		args1 += " " + sv.tools.strings.trim(cmdArgs.substring(argsPos + 6));
+		cmdArgs = cmdArgs.substring(0, argsPos);
+	}
+
+	args1 = sv.tools.strings.trim(args1);
+	if(args1)
+		args1 = " --args " + args1;
+
     var cmd = apps[appId].path;
 	cmd = cmd.replace("%Path%", appPath)
     .replace("%title%", "SciViews-R").replace("%cwd%", cwd)

Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js	2010-10-05 11:20:43 UTC (rev 331)
+++ komodo/SciViews-K/content/js/r.js	2010-10-13 16:09:45 UTC (rev 332)
@@ -425,8 +425,6 @@
 			// After executing, tell R to delete it.
 			var code = sv.getTextRange(what);
 
-			sv.cmdout.append(code);
-
 			if (what == "function") {
 				what += " \"" + code.match("^.*\\S(?=\\s*(?:=|<-)\\s*function)") +
 				"\"";
@@ -1851,18 +1849,21 @@
 
 		var dir = sv.prefs.getString("sciviews.session.dir");
 
-		fileName = sv.tools.fileOpen(dir, objName, "",
+		oFilterIdx = {value: filterIndex};
+
+		fileName = sv.fileOpen(dir, objName, "",
 					["Comma separated values (*.csv)|*.csv",
 					 "Tab delimited (*.txt)|*.txt",
 					 "Whitespace delimited values (*.txt)|*.txt"
-					 ], false, true, filterIndex);
+					 ], false, true, oFilterIdx);
 
-
-		// TODO: set delimiter basing on filterIndex...
+		sep = [",", "\\t", " "][oFilterIdx.value];
+		if(dec == "," && sep == ",") dec=";";
 	}
 
-	var cmd = 'write.table(' + name + ', file="' + fileName.addslashes() +
-		'", dec="' + dec + '", sep="' + sep + '")';
+	var cmd = 'write.table(' + name + ', file="' +
+		sv.tools.strings.addslashes(fileName) +
+		'", dec="' + dec + '", sep="' + sep + '", col.names=NA)';
 	sv.r.eval(cmd);
 	return(cmd);
 }

Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js	2010-10-05 11:20:43 UTC (rev 331)
+++ komodo/SciViews-K/content/js/robjects.js	2010-10-13 16:09:45 UTC (rev 332)
@@ -45,7 +45,7 @@
 ///// Other ////////////////////////////////////////////////////////////////////
 ///// Private methods
 // _createVisibleData () - create visibleData from treeData
-// __addObject(env, objName, callback, obj)
+// _addObject(env, objName, callback, obj)
 // _parseObjectList(data, packSelected)
 // _removeObjectList(pack)
 // _parseSubObjectList(data, obj)
@@ -125,6 +125,11 @@
 		'package', 'standardGeneric', 'S3', 'S4', 'ts', 'environment',
 		'formula'];
 
+
+	// used in .contextOnShow
+	var nonDetachable = [".GlobalEnv", "TempEnv", "package:svGUI", "package:svMisc",
+		"package:svSocket", "package:base"];
+
 	// Reference to parent object for private functions
 	var _this = this;
 
@@ -136,7 +141,6 @@
 
 	this.visibleData = [];
 	this.treeData = [];
-
 	this.treeBox = null;
 	this.selection = null;
 
@@ -164,6 +168,11 @@
 	};
 
 	function _parseObjectList (data, packSelected) {
+		if(typeof _this.searchPaths == "undefined") {
+			_this.getPackageList(true); //TODO call _parseObjectList afterwards
+			return (false);
+		}
+
 		// Get position in the search path
 		function getPos (pack) {
 			var pos, searchPaths = _this.searchPaths;
@@ -270,12 +279,13 @@
 		_createVisibleData();
 	};
 
-	function __addObject(env, objName, callback, obj) {
+	function _addObject(env, objName, callback, obj) {
 		var id = sv.prefs.getString("sciviews.client.id", "SciViewsK");
 
 		var cmd = cmdPattern.replace(/%ID%/g, id).replace(/%ENV%/g, env.addslashes())
 				.replace(/%OBJ%/g, objName.replace(/\$/g, "$$$$"));
 
+		//sv.cmdout.append(cmd);
 		sv.r.evalCallback(cmd, callback, obj);
 	};
 
@@ -613,7 +623,7 @@
 		if (!item) return;
 		if (item.isList && !item.origItem.isOpen &&
 			!item.origItem.childrenLoaded) {
-			__addObject(item.origItem.env, item.origItem.fullName,
+			_addObject(item.origItem.env, item.origItem.fullName,
 						_parseSubObjectList, item);
 
 			return;
@@ -689,21 +699,13 @@
 
 	this.getCellText = function (idx, column) _this.visibleData[idx].labels[column.index];
 	this.isContainer = function (idx) _this.visibleData[idx].isContainer;
-
 	this.isContainerOpen = function (idx) _this.visibleData[idx].origItem.isOpen;
-
 	this.isContainerEmpty = function (idx) _this.visibleData[idx].isContainerEmpty;
-
 	this.isSeparator = function (idx) false;
-
 	this.isSorted = function () false;
-
 	this.isEditable = function (idx, column) false;
-
 	this.getParentIndex = function (idx) this.visibleData[idx].parentIndex;
-
 	this.getLevel = function (idx) this.visibleData[idx].level;
-
 	this.hasNextSibling = function (idx, after) !this.visibleData[idx].last;
 
 	this.getImageSrc = function (row, col) {
@@ -723,15 +725,10 @@
 	};
 
 	this.getCellValue = function (idx, column) {};
-
 	this.cycleHeader = function (col, elem) {};
-
 	this.selectionChanged = function () {};
-
 	this.cycleCell = function (idx, column) {};
-
 	this.performAction = function (action) {};
-
 	this.performActionOnCell = function (action, index, column) {};
 
 	this.getRowProperties = function (idx, props) {
@@ -822,7 +819,7 @@
 
 	this.init = function () {
 		this.visibleData = [];
-		__addObject(".GlobalEnv", "", _parseObjectList, ".GlobalEnv");
+		_addObject(".GlobalEnv", "", _parseObjectList, ".GlobalEnv");
 		this.getPackageList();
 
 		isInitialized = true;
@@ -904,7 +901,7 @@
 		if (!pack)
 			return;
 		if (el.checked) {
-			__addObject(pack, "", _parseObjectList, pack);
+			_addObject(pack, "", _parseObjectList, pack);
 		} else {
 			_removeObjectList(pack);
 		}
@@ -928,7 +925,7 @@
 
 	this.refreshGlobalEnv = function (data) {
 		if(!data) {
-			__addObject(".GlobalEnv", "", _parseObjectList, ".GlobalEnv");
+			_addObject(".GlobalEnv", "", _parseObjectList, ".GlobalEnv");
 		} else {
 			_parseObjectList(data);
 		}
@@ -1131,13 +1128,18 @@
 		var currentIndex = _this.selection.currentIndex;
 
 		if (currentIndex != -1) {
-			var isPackage, noDetach, isFunction;
+			var isEnvironment, isPackage, isInPackage, noDelete, isFunction;
 			var item, type, name;
 			item = _this.visibleData[currentIndex].origItem;
 			type = item.class;
 			name = item.fullName;
 
-			noDetach = isPackage && (name == ".GlobalEnv" || name == "TempEnv");
+			isEnvironment = item.type == "environment";
+			isPackage = isEnvironment && (item.name.indexOf("package:") == 0);
+			isInPackage = !isPackage && item.env && (item.env.indexOf("package:") == 0);
+
+			noDelete = (isEnvironment && (nonDetachable.indexOf(name) != -1))
+				|| isInPackage;
 			isFunction = type == "function";
 
 			var canSaveToFile = ["data.frame", "matrix", "table"]
@@ -1147,26 +1149,38 @@
 
 			// help can be shown only for one object:
 			var hasHelp = (selItemCount == 1)
-				&& ((isPackage && item.name.indexOf("package:") == 0) ||
-					(!isPackage && item.env.indexOf("package:") == 0));
+				&& (isPackage || isInPackage);
 
+			sv.cmdout.append(name
+							 + "; isPackage:" + isPackage
+							 + "; isEnvironment:" + isEnvironment
+							 + "; noDelete:" + noDelete
+							 + "; isInPackage:" + isEnvironment
+							 + "; isFunction:" + isFunction
+							 + "; hasHelp:" + hasHelp
+							 )
+
 			document.getElementById("robjects_cmd_removeobj")
-				.setAttribute("disabled", noDetach);
+				.setAttribute("disabled", noDelete);
+			document.getElementById("robjects_cmd_deletenow")
+				.setAttribute("disabled", noDelete);
+
+
 			//document.getElementById("robjects_cmd_attach")
-			//	.setAttribute("disabled", noDetach || !isPackage);
+			//	.setAttribute("disabled", noDelete || !isPackage);
 			document.getElementById("robjects_cmd_summary")
-				.setAttribute("disabled", isFunction || isPackage);
+				.setAttribute("disabled", isFunction || isEnvironment);
 			document.getElementById("robjects_cmd_print")
 				.setAttribute("disabled", isPackage);
 			document.getElementById("robjects_cmd_plot")
-				.setAttribute("disabled", isFunction || isPackage);
+				.setAttribute("disabled", isFunction || isEnvironment);
 			document.getElementById("robjects_cmd_names")
 				.setAttribute("disabled", isFunction);
 			document.getElementById("robjects_cmd_str")
 				.setAttribute("disabled", isPackage);
 
-			//document.getElementById("robjects_cmd_write_table")
-			//	.setAttribute("disabled", !isDataFrame);
+			document.getElementById("robjects_cmd_write_table")
+				.setAttribute("disabled", !canSaveToFile);
 
 			// Disable help option for non-package objects,
 			// because usually there is none
@@ -1205,8 +1219,8 @@
 			var cmd = [], expr;
 
 			for (i in obj) {
-				expr = "eval(expression(" + obj[i].fullName +
-					"), envir = as.environment(\"" +
+				expr = "evalq(" + obj[i].fullName +
+					", envir = as.environment(\"" +
 					obj[i].env.addslashes() + "\"))";
 
 				sv.r.saveDataFrame(expr, '', obj[i].name);
@@ -1221,8 +1235,8 @@
 		default:
 			var cmd = [];
 			for (i in obj) {
-				cmd.push(action + "(eval(expression(" + obj[i].fullName +
-					"), envir = as.environment(\"" +
+				cmd.push(action + "(evalq(" + obj[i].fullName +
+					", envir = as.environment(\"" +
 					obj[i].env.addslashes() + "\")))");
 			}
 			sv.r.eval(cmd.join("\n"));

Modified: komodo/SciViews-K/defaults/svStart.R
===================================================================
--- komodo/SciViews-K/defaults/svStart.R	2010-10-05 11:20:43 UTC (rev 331)
+++ komodo/SciViews-K/defaults/svStart.R	2010-10-13 16:09:45 UTC (rev 332)
@@ -1,24 +1,47 @@
 ### SciViews install begin ###
 # SciViews-R installation and startup for running R with Komodo/SciViews-K
 # Version 0.9.11, 2010-02-09 Ph. Grosjean (phgrosjean at sciviews.org)
-# Version 0.9.15, 2010-05-01 mod by K. Barton
+# Version 0.9.20, 2010-10-11 mod by K. Barton
 
 # TODO: also use value in koDebug to debug server from within R!
 
 "svStart" <-
-function (minVersion = c(R = "2.11.1", svMisc = "0.9-60",
-svSocket = "0.9-50", svGUI = "0.9-49", MASS = "7.2.0", ellipse = "0.3-5",
-SciViews = "0.9-2"),
+function (minRVersion = "2.11.1", minVersion = NA,
 	# NOTE: minVersion is now also used as a list of required packages
 	remote.repos = "http://R-Forge.R-project.org",
 	pkg.dir = ".",
 	debug = Sys.getenv("koDebug") == "TRUE",
-	pkgsLast = c("svGUI", "ellipse", "MASS", "SciViews") # to be loaded at the end
+	pkgsLast = c("svGUI", "ellipse", "MASS", "SciViews"), # to be loaded at the end,
+	skip = NULL
 	) {
 
 	# needed later for tryCatch'ing:
 	"err.null" <- function (e) return(NULL)
 
+	# If minVersion is not provided, get it from packages in 'default' directory
+	pkg.extpat <- switch(.Platform$pkgType, win.binary = "zip", "tar\\.gz")
+	pkgFiles <- dir(pkg.dir, pattern=pkg.extpat)
+	if (all(is.na(minVersion))) {
+		minVersion <- structure(gsub(sprintf("(^[a-zA-Z]+_|\\.%s$)",
+			pkg.extpat), "", pkgFiles), names=gsub("_.*$", "", pkgFiles))
+
+
+		minVersion <- package_version(gsub(sprintf("(^[a-zA-Z]+_|\\.%s$)",
+			pkg.extpat), "", pkgFiles))
+
+		pkgNames <- gsub("_.*$", "", pkgFiles)
+		# Select newest version if more then one exist
+		v <- tapply(minVersion, pkgNames, max)
+		minVersion <- as.character(structure(v, class=class(minVersion)))
+		names(minVersion) <- names(v)
+	}
+	pkgs <- names(minVersion)
+
+	i.skip <- !(pkgs %in% skip)
+	pkgs <- pkgs[i.skip]
+	minVersion <- minVersion[i.skip]
+	pkgFiles <- pkgFiles[i.skip]
+
 	# TODO: if R crashes before this code is done, 00LOCK remains and it is not
 	# possible to initiate SciViews extensions any more! => use a different
 	# mechanism (perhaps, a file in /tmp and/or make sure the 00LOCK file
@@ -74,12 +97,12 @@
 			if (length(b) > length(a)) return(-1) else return(0)
 		}
 	}
-	rVersion <- paste(R.Version()$major, R.Version()$minor, sep = ".")
-	res <- compareVersion(rVersion, minVersion["R"])
+	rVersion <- as.character(getRversion())
+	res <- compareVersion(rVersion, minRVersion)
 	if (res < 0) {
 		res <- FALSE
 		cat("R is too old for this version of SciViews (R >=",
-			minVersion["R"], "is needed), please, upgrade it\n")
+			minRVersion, "is needed), please, upgrade it\n")
 	} else res <- TRUE
 
 	# Load main R packages (tools added to the list because now required by svMisc)
@@ -189,12 +212,11 @@
 		# Load packages svMisc, svSocket & svGUI (possibly after installing
 		# or upgrading them). User is supposed to agree with this install
 		# from the moment he tries to start and configure R from Komodo Edit
-		pkgs <- names(minVersion)
-		pkgs <- pkgs[!(pkgs %in% "R")]
+		###pkgs <- pkgs[!(pkgs %in% "R")]
 
-		ext <- switch(.Platform$pkgType, # There is a problem on some Macs
-			# => always install from sources there! mac.binary = "\\.tgz",
-			win.binary = "\\.zip", "\\.tar\\.gz")
+		#ext <- switch(.Platform$pkgType, # There is a problem on some Macs
+		#	# => always install from sources there! mac.binary = "\\.tgz",
+		#	win.binary = "\\.zip", "\\.tar\\.gz")
 		typ <- switch(.Platform$pkgType, # There is a problem on some Macs
 			# => always install from sources there! mac.binary = "\\.tgz",
 			win.binary = "win.binary", "source")
@@ -216,21 +238,25 @@
 		debugMsg("Installing packages if needed:")
 		sapply(pkgs, function (pkgName) {
 			debugMsg("Now trying package:", pkgName)
-			file <- dir(path = pkg.dir, pattern = paste(pkgName, ext, sep = ".+"))
+			pkgFile <- dir(path = pkg.dir, pattern = sprintf("%s_.*\\.%s", pkgName,
+				pkg.extpat))
 
-			if (length(file) > 0) {
-				# Better by-version sorting
-				ver <- gsub(paste("(^", pkgName, "_", "|", ext, "$)", sep = ""),
-					"", basename(file))
-				file <- tail(file[order(sapply(strsplit(ver, "[\\.\\-]"),
-					function (x) sum(as.numeric(x) * (100 ^ -seq_along(x)))))], 1)
+			if (length(pkgFile) > 0) {
+
+				pkgVersion <- gsub(sprintf("(^%s_|\\.%s$)", pkgName,  pkg.extpat),
+					"", basename(pkgFile))
+				i <- order(package_version(pkgVersion), decreasing = TRUE)[1]
+				pkgFile <-  pkgFile[i]
+				pkgVersion <-  pkgVersion[i]
+
+
 				# For some reasons (bug probably?) I cannot install a package in
 				# R 2.10.1 under Mac OS X when the path to the package has spaces
 				# Also, correct a bug here when installing package from a
 				# repository where we are not supposed to prepend a path!
 				# Copy the dfile temporarily to the temp dir
-				sourcefile <- file.path(pkg.dir, file)
-				file <- file.path(tempdir(), file)
+				sourcefile <- file.path(pkg.dir, pkgFile)
+				pkgFile <- file.path(tempdir(), pkgFile)
 				repos <- NULL
 
 				# remove directory lock if exists (happens sometimes on linux)
@@ -240,7 +266,7 @@
 			} else {
 				# No packages found, download from the web
 				sourcefile <- NULL
-				file <- pkgName
+				pkgFile <- pkgName
 				repos <- remote.repos
 			}
 
@@ -251,20 +277,22 @@
 				fields = "Version"), minVersion[pkgName]) < 0) {
 				if (!pkgIsInstalled) {
 					cat("Installing missing package", sQuote(pkgName),
+					paste("(version", pkgVersion, ")", sep=""),
 						"into", sQuote(lib), "\n")
 				} else {
-					cat("Updating package", sQuote(pkgName), "\n")
+					cat("Updating package", sQuote(pkgName), "to version",
+						pkgVersion, "\n")
 				}
 				# Copy the install file to the temporary directory
-				if (!is.null(sourcefile)) try(invisible(file.copy(sourcefile, file)))
+				if (!is.null(sourcefile)) try(invisible(file.copy(sourcefile, pkgFile)))
 				# Install or update the package
-				try(install.packages(file, lib = lib, repos = repos, type = typ))
+				try(install.packages(pkgFile, lib = lib, repos = repos, type = typ))
 				# Erase the temporary file
-				try(unlink(file))
+				try(unlink(pkgFile))
 			} else {
 				debugMsg("Package", pkgName, "is up to date")
 			}
-		})
+		}) ## end installing packages
 
 		# Split pkgs to primary and secondary
 		pkgsPrimary <- pkgs[!(pkgs %in% pkgsLast)]
@@ -283,9 +311,9 @@
 
 			if (!res) {
 				cat("Impossible to start the SciViews R socket server\n(socket",
-					getOption("ko.serve"), "already in use?)\n")
-				cat("Solve the problem, then type: require(svGUI)\n")
-				cat("or choose a different port for the server in Komodo\n")
+					getOption("ko.serve"), "already in use?)\n",
+				    "Solve the problem, then type: require(svGUI)\n",
+				    "or choose a different port for the server in Komodo\n")
 
 			} else {
 				# Finally, load svGUI, ellipse, MASS and SciViews
@@ -535,7 +563,7 @@
 				path.expand(getOption("R.initdir")), sep = ""))
 		}
 		# Update info in Komodo:
-		debugMsg("Contacting Komodo with koCmd")
+		debugMsg("Contacting Komodo using 'koCmd'")
 		invisible(koCmd(paste(
 			"sv.socket.rUpdate()",
 			"sv.cmdout.append('R is started')",



More information about the Sciviews-commits mailing list