[education/rkward] /: Check for existence of (custom) library locations, and create them, if needed.

Thomas Friedrichsmeier null at kde.org
Wed Jun 30 16:43:32 BST 2021


Git commit 4d31c9b08b7ce2746bd70971d548286866f8f8d9 by Thomas Friedrichsmeier.
Committed on 30/06/2021 at 15:43.
Pushed by tfry into branch 'master'.

Check for existence of (custom) library locations, and create them, if needed.

M  +1    -1    ChangeLog
M  +0    -1    rkward/rbackend/rkrinterface.cpp
M  +17   -1    rkward/settings/rksettingsmoduler.cpp

https://invent.kde.org/education/rkward/commit/4d31c9b08b7ce2746bd70971d548286866f8f8d9

diff --git a/ChangeLog b/ChangeLog
index 399c0a51..0f9d5abb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,4 @@
-- (Try to) automatically create R user library location, if it does not exist
+- (Try to) automatically create custom R library locations, if they do not exist
 - Workaround for invalid EDITOR variable set by Kate Terminal plugin (also fixed in recent kate)
 - kate plugin related actions are now active whenever a script window is active (not only the corresponding tool window)
   - TODO: support kate plugins in detached windows
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index 0251edcf..1ba560f8 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -413,7 +413,6 @@ void RInterface::handleRequest (RBackendRequest* request) {
 		RCommandChain *chain = openSubcommandChain (runningCommand ());
 
 		issueCommand ("paste (R.version[c (\"major\", \"minor\")], collapse=\".\")\n", RCommand::GetStringVector | RCommand::App | RCommand::Sync, QString (), this, GET_R_VERSION, chain);
-//		issueCommand ("try({userdir<-path.expand(Sys.getenv(\"R_LIBS_USER\")); if(length(userdir)==1L && !file.exists(userdir)) dir.create(userdir) })\n", RCommand::App | RCommand::Sync, QString (), this, 0, chain);
 		// find out about standard library locations
 		issueCommand ("c(path.expand(Sys.getenv(\"R_LIBS_USER\")), .libPaths())\n", RCommand::GetStringVector | RCommand::App | RCommand::Sync, QString (), this, GET_LIB_PATHS, chain);
 		// start help server / determined help base url
diff --git a/rkward/settings/rksettingsmoduler.cpp b/rkward/settings/rksettingsmoduler.cpp
index cedd9a0e..a42b0624 100755
--- a/rkward/settings/rksettingsmoduler.cpp
+++ b/rkward/settings/rksettingsmoduler.cpp
@@ -548,7 +548,23 @@ void RKSettingsModuleRPackages::rCommandDone (RCommand *command) {
 QString RKSettingsModuleRPackages::libLocsCommand () {
 	RK_TRACE (SETTINGS);
 
-	QString command = ".libPaths (unique (c (";
+	// For additional library locations configured inside RKWard, try to create them, as needed.
+	// This is especially important for versioned dirs (which will not exist after upgrading R, for instance)
+	QString command;
+	if (!liblocs.isEmpty()) {
+		bool first = true;
+		command = "local({\naddpaths <- unique (c(";
+		QStringList ll = expandLibLocs(liblocs);
+		foreach (const QString& libloc, ll) {
+			if (first) first = false;
+			else command.append (", ");
+			command.append (RObject::rQuote (libloc));
+		}
+		command.append ("))\nlapply(addpaths, function(p) { if (!dir.exists(p)) try(dir.create(p, recursive=TRUE)) })\n})\n");
+	}
+
+	// For add library locations set "the R way", try to interfere as little as possible.
+	command.append(".libPaths (unique (c (");
 	bool first = true;
 	QStringList ll = libraryLocations ();
 	foreach (const QString& libloc, ll) {


More information about the rkward-tracker mailing list