[rkward/work/workspace_browser_redesign] rkward/core: Fix environment search() re-ordering detection.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Fri Nov 6 09:59:33 UTC 2015


Git commit 34e1538cd0f6e29bc7ae955d4e08a0fd33f95418 by Thomas Friedrichsmeier.
Committed on 06/11/2015 at 08:01.
Pushed by tfry into branch 'work/workspace_browser_redesign'.

Fix environment search() re-ordering detection.

Bug was introduced in 9cab353ebf8b64051cffee556b0eeaba52b9680f .
y# Please enter the commit message for your changes. Lines starting

M  +19   -14   rkward/core/robjectlist.cpp
M  +1    -0    rkward/core/robjectlist.h

http://commits.kde.org/rkward/34e1538cd0f6e29bc7ae955d4e08a0fd33f95418

diff --git a/rkward/core/robjectlist.cpp b/rkward/core/robjectlist.cpp
index 5b74adb..0f803a0 100644
--- a/rkward/core/robjectlist.cpp
+++ b/rkward/core/robjectlist.cpp
@@ -51,6 +51,7 @@ RObjectList::RObjectList () : RContainerObject (0, QString ()) {
 	//update_timer->start (AUTO_UPDATE_INTERVAL, true);
 	
 	type = RObject::Workspace;
+	name = "search()";
 	
 	update_chain = 0;
 
@@ -70,6 +71,10 @@ RObjectList::~RObjectList () {
 	delete globalenv;
 }
 
+QString RObjectList::getObjectDescription () const {
+	return i18n ("This section contains environments that are not part of <i>.GlobalEnv</i> / your \"workspace\". Most importantly, this includes loaded packages, but also objects added to R's <i>search()<i>-path using <i>attach()</i>.");
+}
+
 QStringList RObjectList::detachPackages (const QStringList &packages, RCommandChain *chain, RKProgressControl* control) {
 	RK_TRACE (OBJECTS);
 
@@ -161,31 +166,31 @@ void RObjectList::rCommandDone (RCommand *command) {
 	}
 }
 
-void RObjectList::updateEnvironments (const QStringList &env_names, bool force_globalenv_update) {
+void RObjectList::updateEnvironments (const QStringList &_env_names, bool force_globalenv_update) {
 	RK_TRACE (OBJECTS);
 
 	RObjectMap newchildmap;
+	QStringList env_names = _env_names;
+	if (!env_names.isEmpty ()) {
+		QString dummy = env_names.takeFirst ();
+		RK_ASSERT (dummy == ".GlobalEnv");
+		if (force_globalenv_update) {
+			// for now, we only update the .GlobalEnv. All others we assume to be static
+			getGlobalEnv ()->updateFromR (update_chain);
+		}
+	} else {
+		RK_ASSERT (!env_names.isEmpty ());
+	}
 
 	// find which items are new, and copy the old ones
 	for (int i = 0; i < env_names.count (); ++i) {
 		QString name = env_names[i];
 
-		RObject *obj;
-		if (i == 0) {
-			RK_ASSERT (name == ".GlobalEnv");
-			obj = globalenv;
-		} else {
-			obj = findChildByName (name);
-		}
+		RObject *obj = findChildByName (name);
 		if (obj && (i > 0) && (env_names.lastIndexOf (name, i-1) > -1)) {		// duplicate environment names can happen (e.g. if a data.frame is attached multiple times)
 			obj = 0;	// only copy the old item once
 		}
-		if (obj) {
-			// for now, we only update the .GlobalEnv. All others we assume to be static
-			if (obj->isType (GlobalEnv) && force_globalenv_update) {
-				obj->updateFromR (update_chain);
-			}
-		} else {
+		if (!obj) {
 			obj = createTopLevelEnvironment (name);
 			RKGlobals::tracker ()->beginAddObject (obj, this, i);
 			childmap.insert (i, obj);
diff --git a/rkward/core/robjectlist.h b/rkward/core/robjectlist.h
index 61fc373..e79d259 100644
--- a/rkward/core/robjectlist.h
+++ b/rkward/core/robjectlist.h
@@ -67,6 +67,7 @@ public:
 	QStringList detachPackages (const QStringList &packages, RCommandChain *chain = 0, RKProgressControl *control = 0);
 	/** A pseudo object containing as children all loaded namespaces which do not belong to a package on the search path */
 	RKOrphanNamespacesObject* orphanNamespacesObject () const { return orphan_namespaces; };
+	QString getObjectDescription () const;
 public slots:
 	void timeout ();
 signals:



More information about the rkward-tracker mailing list