[education/rkward] /: Fix the issues with require() that were introduced by inlined progress control

Thomas Friedrichsmeier null at kde.org
Sun May 1 21:37:49 BST 2022


Git commit c9d09d3064388a35bd1ad649ef59559dfa5a94c9 by Thomas Friedrichsmeier.
Committed on 01/05/2022 at 20:36.
Pushed by tfry into branch 'master'.

Fix the issues with require() that were introduced by inlined progress control

M  +0    -2    ChangeLog
M  +1    -1    VERSION.cmake
M  +15   -11   rkward/dialogs/rkloadlibsdialog.cpp
M  +3    -2    rkward/rbackend/rkrbackend.cpp
M  +1    -0    rkward/rbackend/rkrbackendprotocol_shared.cpp
M  +2    -1    rkward/rbackend/rkrbackendprotocol_shared.h
M  +1    -1    rkward/rbackend/rpackages/rkward/DESCRIPTION
M  +3    -1    rkward/rbackend/rpackages/rkward/R/base_overrides.R
M  +7    -3    rkward/rbackend/rpackages/rkward/R/rk.print-functions.R

https://invent.kde.org/education/rkward/commit/c9d09d3064388a35bd1ad649ef59559dfa5a94c9

diff --git a/ChangeLog b/ChangeLog
index 51c9d03e..781798bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,11 +3,9 @@ TODOs:
 
 - Fixed some problems with cancelling running commands
 - Package installation uses inline widget to provide progress feedback, instead of separate dialogs
-  - TODO: Finding package from require() fails, because list is not yet loaded
   - TODO: Remove "Ok" button from dialog, rename "Cancel" to "Close"
   - TODO: Remove current repositories from .rk.get.package.installation.status() (no longer needed)
 - Package installation no longer uses an external process, unless required for root permissions
-  - TODO: swallow installation output in require()
 - Fixed: Package installation as root would fail to find kdesu/kdesudo on recent systems
 - Fixed: R help pages would refuse to open in new tab
 - (Re-)added improved "Import Assistant" to help getting started with importing data
diff --git a/VERSION.cmake b/VERSION.cmake
index e0ed9a6d..35521b43 100644
--- a/VERSION.cmake
+++ b/VERSION.cmake
@@ -1,3 +1,3 @@
 # DO NOT CHANGE THIS FILE MANUALLY!
 # It will be overwritten by scripts/set_dist_version.sh
-SET(RKVERSION_NUMBER 0.7.3z+0.7.4+devel1)
+SET(RKVERSION_NUMBER 0.7.3z+0.7.4+devel2)
diff --git a/rkward/dialogs/rkloadlibsdialog.cpp b/rkward/dialogs/rkloadlibsdialog.cpp
index b6f502d0..78b40681 100644
--- a/rkward/dialogs/rkloadlibsdialog.cpp
+++ b/rkward/dialogs/rkloadlibsdialog.cpp
@@ -714,18 +714,22 @@ void InstallPackagesWidget::filterChanged () {
 void InstallPackagesWidget::trySelectPackages (const QStringList &package_names) {
 	RK_TRACE (DIALOGS);
 
-	QStringList failed_names;
-	for (int i = 0; i < package_names.size(); ++i) {
-		QModelIndex index = packages_status->markPackageForInstallation(package_names[i]);
-		if (!index.isValid()) {
-			failed_names.append(package_names[i]);
-		} else {
-			packages_view->scrollTo(model->mapFromSource(index));
+	RCommand *dummy = new RCommand(QString(), RCommand::EmptyCommand); // dummy command will finish, after initialization is complete
+	connect(dummy->notifier(), &RCommandNotifier::commandFinished, this, [this, package_names]() {
+		QStringList failed_names;
+		for (int i = 0; i < package_names.size(); ++i) {
+			QModelIndex index = packages_status->markPackageForInstallation(package_names[i]);
+			if (!index.isValid()) {
+				failed_names.append(package_names[i]);
+			} else {
+				packages_view->scrollTo(model->mapFromSource(index));
+			}
 		}
-	}
-	if (!failed_names.isEmpty()) {
-		KMessageBox::sorry (0, i18n ("The following package(s) requested by the backend have not been found in the package repositories: \"%1\". Maybe the package name was mis-spelled. Or maybe you need to add additional repositories via the \"Configure Repositories\" button.", failed_names.join("\", \"")), i18n ("Package not available"));
-	}
+		if (!failed_names.isEmpty()) {
+			KMessageBox::sorry (0, i18n ("The following package(s) requested by the backend have not been found in the package repositories: \"%1\". Maybe the package name was mis-spelled. Or maybe you need to add additional repositories via the \"Configure Repositories\" button.", failed_names.join("\", \"")), i18n ("Package not available"));
+		}
+	});
+	RInterface::issueCommand(dummy, parent->chain);
 }
 
 void InstallPackagesWidget::markAllUpdates () {
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index 2c86cb90..b80e8361 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -1044,7 +1044,7 @@ SEXP doCopyNoEval (SEXP fromname, SEXP fromenv, SEXP toname, SEXP toenv) {
 	return (R_NilValue);
 }
 
-SEXP doCaptureOutput (SEXP mode, SEXP capture_messages, SEXP capture_output, SEXP suppress_messages, SEXP suppress_output) {
+SEXP doCaptureOutput (SEXP mode, SEXP capture_messages, SEXP capture_output, SEXP suppress_messages, SEXP suppress_output, SEXP allow_nesting) {
 	RK_TRACE (RBACKEND);
 
 	if (RKRSupport::SEXPToInt (mode) == 1) {
@@ -1053,6 +1053,7 @@ SEXP doCaptureOutput (SEXP mode, SEXP capture_messages, SEXP capture_output, SEX
 		if (RKRSupport::SEXPToInt (capture_output)) cm |= RKROutputBuffer::RecordOutput;
 		if (RKRSupport::SEXPToInt (suppress_messages)) cm |= RKROutputBuffer::SuppressMessages;
 		if (RKRSupport::SEXPToInt (suppress_output)) cm |= RKROutputBuffer::SuppressOutput;
+		if (!RKRSupport::SEXPToInt (allow_nesting)) cm |= RKROutputBuffer::NoNesting;
 		RKRBackend::this_pointer->pushOutputCapture (cm);
 		return (R_NilValue);
 	} else {
@@ -1149,7 +1150,7 @@ bool RKRBackend::startR () {
 		{ "rk.show.files", (DL_FUNC) (void*) &doShowFiles, 5 },
 		{ "rk.dialog", (DL_FUNC) (void*) &doDialog, 7 },
 		{ "rk.update.locale", (DL_FUNC) (void*) &doUpdateLocale, 0 },
-		{ "rk.capture.output", (DL_FUNC) (void*) &doCaptureOutput, 5 },
+		{ "rk.capture.output", (DL_FUNC) (void*) &doCaptureOutput, 6 },
 		{ "rk.graphics.device", (DL_FUNC) (void*) &RKStartGraphicsDevice, 7},
 		{ "rk.graphics.device.resize", (DL_FUNC) (void*) &RKD_AdjustSize, 2},
 		{ 0, 0, 0 }
diff --git a/rkward/rbackend/rkrbackendprotocol_shared.cpp b/rkward/rbackend/rkrbackendprotocol_shared.cpp
index 03a14192..cba80805 100644
--- a/rkward/rbackend/rkrbackendprotocol_shared.cpp
+++ b/rkward/rbackend/rkrbackendprotocol_shared.cpp
@@ -183,6 +183,7 @@ bool RKROutputBuffer::handleOutput (const QString &output, int buf_length, ROutp
 			if (cap.mode & RecordMessages) appendToOutputList (&(cap.recorded), output, output_type);
 			if (cap.mode & SuppressMessages) return previously_empty;
 		}
+		if (cap.mode & NoNesting) break;
 	}
 
 	appendToOutputList (&output_buffer, output, output_type);
diff --git a/rkward/rbackend/rkrbackendprotocol_shared.h b/rkward/rbackend/rkrbackendprotocol_shared.h
index c5111bbe..750398e7 100644
--- a/rkward/rbackend/rkrbackendprotocol_shared.h
+++ b/rkward/rbackend/rkrbackendprotocol_shared.h
@@ -142,7 +142,8 @@ public:
 		RecordMessages = 1,
 		RecordOutput = 2,
 		SuppressMessages = 4,
-		SuppressOutput = 8
+		SuppressOutput = 8,
+		NoNesting = 16
 	};
 	void pushOutputCapture (int capture_mode);
 	QString popOutputCapture (bool highlighted);
diff --git a/rkward/rbackend/rpackages/rkward/DESCRIPTION b/rkward/rbackend/rpackages/rkward/DESCRIPTION
index e751b289..7188c414 100755
--- a/rkward/rbackend/rpackages/rkward/DESCRIPTION
+++ b/rkward/rbackend/rpackages/rkward/DESCRIPTION
@@ -18,7 +18,7 @@ Authors at R: c(person(given="Thomas", family="Friedrichsmeier",
         role=c("aut")), person(given="the RKWard team",
         email="rkward-devel at kde.org", role=c("cre","ctb")))
 Version: 0.7.4
-Date: 2022-04-12
+Date: 2022-05-01
 RoxygenNote: 7.1.2
 Collate: 
     'base_overrides.R'
diff --git a/rkward/rbackend/rpackages/rkward/R/base_overrides.R b/rkward/rbackend/rpackages/rkward/R/base_overrides.R
index 4760b67f..98694df9 100644
--- a/rkward/rbackend/rpackages/rkward/R/base_overrides.R
+++ b/rkward/rbackend/rpackages/rkward/R/base_overrides.R
@@ -23,7 +23,9 @@
 	}
 	if (!suppressWarnings(base::require(as.character(package), quietly = quietly, character.only = TRUE, ...))) {
 		if (missing (package)) stop ("No package name given")
-		.rk.do.call("require", as.character(package))
+		rk.capture.output(allow.nesting=FALSE)
+		try(.rk.do.call("require", as.character(package)))
+		rk.end.capture.output()
 		invisible(base::require(as.character(package), quietly = TRUE, character.only = TRUE, ...))
 	} else {
 		invisible(TRUE)
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
index d71853c0..0aa8a2e8 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
@@ -275,6 +275,10 @@
 #'
 #' And arbitrary number of ouptut captures can be started and stopped, and these will form a push/pop stack.
 #'
+#' @param suppress.messages
+#' @param suppress.output output / message are not sent on, neither to surrounding captures, nor as regular output
+#' @param allow.nesting if false, output / message is not sent to surrounding captures, but is sent to regular output (unless suppressed)
+#'
 #' \code{rk.capture.output} Starts capturing output.
 #' 
 #' \code{rk.end.capture.output} Stops capturing output, and returns the recorded output in a string.
@@ -283,13 +287,13 @@
 #'
 #' @export
 #' @rdname rk.capture.output
-"rk.capture.output" <- function (capture.messages = TRUE, capture.output = TRUE, suppress.messages = FALSE, suppress.output = FALSE) {
-	.Call ("rk.capture.output", 1, isTRUE (capture.messages), isTRUE (capture.output), isTRUE (suppress.messages), isTRUE (suppress.output), PACKAGE="(embedding)");
+"rk.capture.output" <- function (capture.messages = TRUE, capture.output = TRUE, suppress.messages = FALSE, suppress.output = FALSE, allow.nesting = TRUE) {
+	.Call ("rk.capture.output", 1, isTRUE (capture.messages), isTRUE (capture.output), isTRUE (suppress.messages), isTRUE (suppress.output), isTRUE (allow.nesting), PACKAGE="(embedding)");
 	invisible (NULL)
 }
 
 #' @export
 #' @rdname rk.capture.output
 "rk.end.capture.output" <- function (highlight = FALSE) {
-	.Call ("rk.capture.output", if (isTRUE (highlight)) 2 else 3, FALSE, FALSE, FALSE, FALSE, PACKAGE="(embedding)");
+	.Call ("rk.capture.output", if (isTRUE (highlight)) 2 else 3, FALSE, FALSE, FALSE, FALSE, FALSE, PACKAGE="(embedding)");
 }



More information about the rkward-tracker mailing list