[education/rkward/devel/workspace_output] /: Before adding new functions to the rkward package, clean up a bit...

Thomas Friedrichsmeier null at kde.org
Sat Oct 10 09:18:44 BST 2020


Git commit 7a208c7b770e84b37875c782222b7ca89e62f13e by Thomas Friedrichsmeier.
Committed on 27/06/2017 at 15:23.
Pushed by tfry into branch 'devel/workspace_output'.

Before adding new functions to the rkward package, clean up a bit...

M  +1    -0    ChangeLog
M  +5    -3    rkward/rbackend/rkrbackend.cpp
M  +1    -1    rkward/rbackend/rkrbackend.h
M  +8    -14   rkward/rbackend/rkrinterface.cpp
M  +4    -1    rkward/rbackend/rkrinterface.h
M  +0    -4    rkward/rbackend/rpackages/rkward/NAMESPACE
M  +1    -0    rkward/rbackend/rpackages/rkward/R/base_overrides.R
M  +6    -10   rkward/rbackend/rpackages/rkward/R/internal.R
M  +2    -1    rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
M  +2    -12   rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
M  +2    -1    rkward/rbackend/rpackages/rkward/man/rk.get.tempfile.name.Rd
M  +1    -1    rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R

https://invent.kde.org/education/rkward/commit/7a208c7b770e84b37875c782222b7ca89e62f13e

diff --git a/ChangeLog b/ChangeLog
index e30191d6..acb81cb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 TODO: Check for duplicated factor levels in data editor, as these are no longer allowed in R
 
+- Hide or remove several purely internal functions (most can still be assessed from the rkward namespace as rkward:::xyz())
 - Implement "split view" feature, allowing to partion the main window, and to hvae several views of the same files / data side-by-side
 - Fixed: Creating trellis on-screen plots, while package lattice is not on the search path would produce errors in plot history mechanism
 - Limit the number of debug log-files to keep (at most three, each, for frontend and backend)
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index 48512505..bea3de91 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -883,9 +883,10 @@ SEXP doSubstackCall (SEXP call) {
 	} */
 
 
-	RKRBackend::this_pointer->handleHistoricalSubstackRequest (list);
+	QStringList ret = RKRBackend::this_pointer->handleHistoricalSubstackRequest (list).toStringList ();
 
-	return R_NilValue;
+	if (ret.isEmpty ()) return R_NilValue;
+	return RKRSupport::StringListToSEXP (ret);
 }
 
 SEXP doPlainGenericRequest (SEXP call, SEXP synchronous) {
@@ -1537,13 +1538,14 @@ RCommandProxy* RKRBackend::fetchNextCommand () {
 	return (handleRequest (&req, false));
 }
 
-void RKRBackend::handleHistoricalSubstackRequest (const QStringList &list) {
+QVariant RKRBackend::handleHistoricalSubstackRequest (const QStringList &list) {
 	RK_TRACE (RBACKEND);
 
 	RBackendRequest request (true, RBackendRequest::HistoricalSubstackRequest);
 	request.params["call"] = list;
 	request.command = current_command;
 	handleRequest (&request);
+	return request.params.value ("return");
 }
 
 QStringList RKRBackend::handlePlainGenericRequest (const QStringList &parameters, bool synchronous) {
diff --git a/rkward/rbackend/rkrbackend.h b/rkward/rbackend/rkrbackend.h
index 44a056f6..929c6753 100644
--- a/rkward/rbackend/rkrbackend.h
+++ b/rkward/rbackend/rkrbackend.h
@@ -107,7 +107,7 @@ public:
 	void handleRequest (RBackendRequest *request) { handleRequest (request, true); };
 /** A relic of history. In contrast to handlePlainGenericRequest(), these requests support running sub-commands. However, the remaining requests which are currently handled this way
 should probably be converted to dedicated RKRBackendRequest's in the future. See also handlePlainGenericRequest(). */
-	void handleHistoricalSubstackRequest (const QStringList &list);
+	QVariant handleHistoricalSubstackRequest (const QStringList &list);
 /** Sends a request to the frontend and returns the result (an empty QStringList in case of asynchronous requests). Note that this function has considerable overlap with
 handleHistoricalSubstackRequest(). Exactly which requests get handled by which function is somewhat arbitrary, ATM. However, request that do not need sub-commands to be run, should generally be converted to use handlePlainGenericRequest(). (And probably all historicalSubstackRequests should be replaced!) */
 	QStringList handlePlainGenericRequest (const QStringList &parameters, bool synchronous);
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index 3bc4c296..ba3a53e0 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -384,7 +384,7 @@ void RInterface::handleRequest (RBackendRequest* request) {
 			}
 		}
 		command_requests.append (request);
-		processHistoricalSubstackRequest (request->params["call"].toStringList (), parent);
+		processHistoricalSubstackRequest (request->params["call"].toStringList (), parent, request);
 	} else if (request->type == RBackendRequest::PlainGenericRequest) {
 		request->params["return"] = QVariant (processPlainGenericRequest (request->params["call"].toStringList ()));
 		RKRBackendProtocolFrontend::setRequestCompleted (request);
@@ -681,7 +681,7 @@ QStringList RInterface::processPlainGenericRequest (const QStringList &calllist)
 	return QStringList ();
 }
 
-void RInterface::processHistoricalSubstackRequest (const QStringList &calllist, RCommand *parent_command) {
+void RInterface::processHistoricalSubstackRequest (const QStringList &calllist, RCommand *parent_command, RBackendRequest *request) {
 	RK_TRACE (RBACKEND);
 
 	RCommandChain *in_chain;
@@ -739,14 +739,10 @@ void RInterface::processHistoricalSubstackRequest (const QStringList &calllist,
 		QStringList object_list = calllist.mid (1);
 		new RKEditObjectAgent (object_list, in_chain);
 	} else if (call == "require") {
-		if (calllist.count () >= 2) {
-			QString lib_name = calllist[1];
-			KMessageBox::information (0, i18n ("The R-backend has indicated that in order to carry out the current task it needs the package '%1', which is not currently installed. We will open the package-management tool, and there you can try to locate and install the needed package.", lib_name), i18n ("Require package '%1'", lib_name));
-			RKLoadLibsDialog::showInstallPackagesModal (0, in_chain, lib_name);
-			issueCommand (".rk.set.reply (\"\")", RCommand::App | RCommand::Sync, QString (), 0, 0, in_chain);
-		} else {
-			issueCommand (".rk.set.reply (\"Too few arguments in call to require.\")", RCommand::App | RCommand::Sync, QString (), 0, 0, in_chain);
-		}
+		RK_ASSERT (calllist.count () == 2);
+		QString lib_name = calllist.value (1);
+		KMessageBox::information (0, i18n ("The R-backend has indicated that in order to carry out the current task it needs the package '%1', which is not currently installed. We will open the package-management tool, and there you can try to locate and install the needed package.", lib_name), i18n ("Require package '%1'", lib_name));
+		RKLoadLibsDialog::showInstallPackagesModal (0, in_chain, lib_name);
 	} else if (call == "doPlugin") {
 		if (calllist.count () >= 3) {
 			QString message;
@@ -757,15 +753,13 @@ void RInterface::processHistoricalSubstackRequest (const QStringList &calllist,
 			ok = RKComponentMap::invokeComponent (calllist[1], calllist.mid (3), mode, &message, in_chain);
 
 			if (!message.isEmpty ()) {
-				QString type = "warning";
-				if (!ok) type = "error";
-				issueCommand (".rk.set.reply (list (type=\"" + type + "\", message=\"" + RKCommonFunctions::escape (message) + "\"))", RCommand::App | RCommand::Sync, QString (), 0, 0, in_chain);
+				request->params["return"] = QVariant (QStringList (ok ? QStringLiteral ("warning") : QStringLiteral ("error")) << message);
 			}
 		} else {
 			RK_ASSERT (false);
 		}
 	} else {
-		issueCommand ("stop (\"Unrecognized call '" + call + "'. Ignoring\")", RCommand::App | RCommand::Sync, QString (), 0, 0, in_chain);
+		request->params["return"] = QVariant (QStringList (QStringLiteral ("error")) << i18n ("Unrecognized call '%1'", call));
 	}
 	
 	closeChain (in_chain);
diff --git a/rkward/rbackend/rkrinterface.h b/rkward/rbackend/rkrinterface.h
index fa286286..dc73d803 100644
--- a/rkward/rbackend/rkrinterface.h
+++ b/rkward/rbackend/rkrinterface.h
@@ -92,8 +92,11 @@ private:
 		RecordingCommandsUnfiltered
 	} command_logfile_mode;
 
-	void processHistoricalSubstackRequest (const QStringList &calllist, RCommand *parent_command);
+/** helper function to handle backend requests that (may) involve running additional R-"sub"-commands. TODO; This should probably be merged with processRBackendRequest.*/
+	void processHistoricalSubstackRequest (const QStringList &calllist, RCommand *parent_command, RBackendRequest *request);
+/** helper function to handle the bulk backend of requests that do not involve running sub-commands, and need a return value that can easily be represented in a QStringList() */
 	QStringList processPlainGenericRequest (const QStringList &calllist);
+/** helper function to handle backend requests that do not inolve running sub-commands. */
 	void processRBackendRequest (RBackendRequest *request);
 
 /** A list of all commands that have entered, and not yet left, the backend thread */
diff --git a/rkward/rbackend/rpackages/rkward/NAMESPACE b/rkward/rbackend/rpackages/rkward/NAMESPACE
index 5b1e0595..1705032d 100644
--- a/rkward/rbackend/rpackages/rkward/NAMESPACE
+++ b/rkward/rbackend/rpackages/rkward/NAMESPACE
@@ -9,9 +9,7 @@ export(.rk.cat.output)
 export(.rk.data.frame.delete.row)
 export(.rk.data.frame.insert.column)
 export(.rk.data.frame.insert.row)
-export(.rk.do.call)
 export(.rk.do.error)
-export(.rk.do.plain.call)
 export(.rk.find.package.pluginmaps)
 export(.rk.fix.assignments)
 export(.rk.fix.assignments.graphics)
@@ -30,12 +28,10 @@ export(.rk.inside.rkward.session)
 export(.rk.killPreviewDevice)
 export(.rk.make.hr)
 export(.rk.make.short.name)
-export(.rk.make.watch.f)
 export(.rk.rerun.plugin.link)
 export(.rk.set.invalid.fields)
 export(.rk.set.levels)
 export(.rk.set.meta)
-export(.rk.set.reply)
 export(.rk.set.vector.mode)
 export(.rk.startPreviewDevice)
 export(.rk.try.get.namespace)
diff --git a/rkward/rbackend/rpackages/rkward/R/base_overrides.R b/rkward/rbackend/rpackages/rkward/R/base_overrides.R
index 8f10b56c..b333f73b 100644
--- a/rkward/rbackend/rpackages/rkward/R/base_overrides.R
+++ b/rkward/rbackend/rpackages/rkward/R/base_overrides.R
@@ -20,6 +20,7 @@
 		package <- as.character(substitute(package))
 	}
 	if (!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))
 		invisible(base::require(as.character(package), quietly = TRUE, character.only = TRUE, ...))
 	} else {
diff --git a/rkward/rbackend/rpackages/rkward/R/internal.R b/rkward/rbackend/rpackages/rkward/R/internal.R
index f08fe20a..392dad74 100644
--- a/rkward/rbackend/rpackages/rkward/R/internal.R
+++ b/rkward/rbackend/rpackages/rkward/R/internal.R
@@ -121,17 +121,14 @@
 	}
 }
 
-#' @export
-".rk.set.reply" <- function (x) .rk.variables$.rk.rkreply <- x
-
-#' @export
 ".rk.do.call" <- function (x, args=NULL) {
-	.rk.set.reply (NULL)
-	.Call ("rk.do.command", c (x, args), PACKAGE="(embedding)");
-	return (.rk.variables$.rk.rkreply)
+	ret <- .Call ("rk.do.command", c (x, args), PACKAGE="(embedding)");
+	if (!is.null (ret)) {
+		if (ret[1] == "warning") warning (ret[2])
+		else stop (ret[2])
+	}
 }
 
-#' @export
 ".rk.do.plain.call" <- function (x, args=NULL, synchronous=TRUE) {
 	.Call ("rk.do.generic.request", c (x, args), isTRUE (synchronous), PACKAGE="(embedding)")
 }
@@ -230,7 +227,6 @@
 #' @export
 ".rk.watched.symbols" <- new.env ()
 
-#' @export
 ".rk.make.watch.f" <- function (k) {
 	# we need to make sure, the functions we use are *not* looked up as symbols in .GlobalEnv.
 	# else, for instance, if the user names a symbol "missing", and we try to resolve it in the
@@ -239,7 +235,7 @@
 	get <- base::get
 	missing <- base::missing
 	assign <- base::assign
-	.rk.do.call <- rkward::.rk.do.call
+	.Call <- base::.Call
 	invisible <- base::invisible
 
 	function (value) {
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
index a4763254..f8d3c0da 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
@@ -7,7 +7,8 @@
 #' the current (or specified) html file, and re-initialize it.
 #' 
 #' \code{rk.get.tempfile.name} returns a non-existing filename inside the
-#' directory of the output file. The filename is returned as an absolute path,
+#' specified directory (or the directory of the current output file, if the parameter is
+#' omitted / left empty). The filename is returned as an absolute path,
 #' but the relative path with respect to the base directory can be obtained via
 #' \code{names()}. It is mainly used by \link{rk.graph.on} to
 #' create filenames suitable for storing images in the output. The filenames of
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
index 191612b8..1fa81bdf 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
@@ -72,17 +72,7 @@
 	}
 
 	# do call
-	res <- .rk.do.call ("doPlugin", callstrings)
-
-	# handle result
-	if (!is.null (res)) {
-		if (res$type == "warning") {
-			warning (res$message)
-		} else {
-			stop (res$message)
-		}
-	}
-
+	.rk.do.call ("doPlugin", callstrings)
 	invisible (TRUE)
 }
 
@@ -90,7 +80,7 @@
 #'
 #' @param pluginmap.files a character vector of file names to add. This may be left empty,
 #'                        if the only desired effect is to reload all active pluginmaps.
-#' @param force.add logical. Whether the pluginmap files should also be added, if they had
+#' @param force.add logical. Whether the pluginmap files should also be added, if# they had
 #'                  been previously de-selected in the settings menu, and regardless of their
 #'                  priority setting. In scripted usage, this should generally be set to FALSE.
 #' @param force.reload logical. By default the active pluginmaps are reloaded, only if any new ones
diff --git a/rkward/rbackend/rpackages/rkward/man/rk.get.tempfile.name.Rd b/rkward/rbackend/rpackages/rkward/man/rk.get.tempfile.name.Rd
index 2d61db2c..810763bd 100644
--- a/rkward/rbackend/rpackages/rkward/man/rk.get.tempfile.name.Rd
+++ b/rkward/rbackend/rpackages/rkward/man/rk.get.tempfile.name.Rd
@@ -66,7 +66,8 @@ the current (or specified) html file, and re-initialize it.
 }
 \details{
 \code{rk.get.tempfile.name} returns a non-existing filename inside the
-directory of the output file. The filename is returned as an absolute path,
+specified directory (or the directory of the current output file, if the parameter is
+omitted / left empty). The filename is returned as an absolute path,
 but the relative path with respect to the base directory can be obtained via
 \code{names()}. It is mainly used by \link{rk.graph.on} to
 create filenames suitable for storing images in the output. The filenames of
diff --git a/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R b/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R
index 9b9f2f4e..27e79600 100644
--- a/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R
+++ b/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R
@@ -257,7 +257,7 @@ rktest.initializeEnvironment <- function () {
 	rktest.replace ("rk.set.output.html.file", function (x) {
 		stopifnot(is.character(x))
 		assign(".rk.output.html.file", x, .rk.variables)
-		.rk.do.plain.call ("set.output.file", c (x, "SILENT"), synchronous=FALSE)
+		rkward:::.rk.do.plain.call ("set.output.file", c (x, "SILENT"), synchronous=FALSE)
 	})
 	assign("initialized", TRUE, envir=.rktest.tmp.storage)
 }




More information about the rkward-tracker mailing list