[education/rkward] rkward/rbackend/rpackages/rkward/R: added code to make the removal of NULL default values not a breaking change to affected functions

m.eik michalke null at kde.org
Mon Sep 11 21:23:41 BST 2023


Git commit c022a453d10fd63879c5df6accae8e9d66dc9d21 by m.eik michalke.
Committed on 11/09/2023 at 22:19.
Pushed by meikm into branch 'master'.

added code to make the removal of NULL default values not a breaking change to affected functions

it could be that some other code or scripts use the old NULL values explicitly as a feature.
now, if the arguments in questions are given a NULL value, a warning will ne shown that
this is now deprecated, and the verable will be made missing so the rest of the function
behaves as expected.

M  +15   -1    rkward/rbackend/rpackages/rkward/R/public_graphics.R
M  +37   -24   rkward/rbackend/rpackages/rkward/R/rk.KDE_GUI-functions.R
M  +7    -0    rkward/rbackend/rpackages/rkward/R/rk.demo.R
M  +14   -0    rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R
M  +7    -0    rkward/rbackend/rpackages/rkward/R/rk.label-functions.R
M  +7    -0    rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
M  +7    -0    rkward/rbackend/rpackages/rkward/R/rk.utility-functions.R
M  +20   -0    rkward/rbackend/rpackages/rkward/R/rk.workspace-functions.R

https://invent.kde.org/education/rkward/-/commit/c022a453d10fd63879c5df6accae8e9d66dc9d21

diff --git a/rkward/rbackend/rpackages/rkward/R/public_graphics.R b/rkward/rbackend/rpackages/rkward/R/public_graphics.R
index b9ed66fe8..c71ba26df 100644
--- a/rkward/rbackend/rpackages/rkward/R/public_graphics.R
+++ b/rkward/rbackend/rpackages/rkward/R/public_graphics.R
@@ -460,7 +460,14 @@
 		# callUHA is not really utilized, but there to provide a flixibility to not call 
 		# .rk.update.hist.action () when not needed
 		devId <- as.character (devId)
-		
+
+		# for the time being, translate NULL into missingness and throw a warning
+		if(!missing(isManaged)){
+			if (is.null (isManaged)) {
+				warning("Deprecated: isManaged = NULL, leave missing if unused!")
+				isManaged <- substitute()
+			}
+		}
 		if (missing (isManaged)) isManaged <- .is.device.managed (devId)
 		if (!isManaged) return (invisible ())
 		
@@ -819,6 +826,13 @@
 	{
 		message ("History length   : ", sP.length)
 		message ("History size (KB): ", round (object.size (savedPlots) / 1024, 2))
+		# for the time being, translate NULL into missingness and throw a warning
+		if(!missing(devId)){
+			if (is.null (devId)) {
+				warning("Deprecated: devId = NULL, leave missing if unused!")
+				devId <- substitute()
+			}
+		}
 		if (missing (devId)) {
 			.tmp.df <- data.frame (
 				pNew = sapply (histPositions, "[[", "is.this.plot.new"),
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.KDE_GUI-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.KDE_GUI-functions.R
index bff7057a4..f734e625e 100755
--- a/rkward/rbackend/rpackages/rkward/R/rk.KDE_GUI-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.KDE_GUI-functions.R
@@ -172,33 +172,46 @@
 #' @export
 #' @rdname rk.show.messages
 "rk.select.list" <- function (choices, preselect, multiple = FALSE, title) {
-    if (missing (preselect)) {
-        preselect <- character(0)
-    } else {
-        preselect <- as.character (preselect)
+  # for the time being, translate NULL into missingness and throw a warning
+  if(!missing(preselect)){
+    if (is.null (preselect)) {
+      warning("Deprecated: preselect = NULL, leave missing if unused!")
+      preselect <- substitute()
     }
-	preselect.len = length (preselect)
-	choices <- as.character (choices)
-	choices.len <- length (choices)
-	params <- list ()
+  }
+  if (missing (preselect)) {
+      preselect <- character(0)
+  } else {
+      preselect <- as.character (preselect)
+  }
+  preselect.len = length (preselect)
+  choices <- as.character (choices)
+  choices.len <- length (choices)
+  params <- list ()
 
-	# serialize all parameters
-	params[1] <- if(missing (title)) "" else as.character (title)
-	if (multiple) params[2] <- "multi"
-	else params[2] <- "single"
-	params[3] <- as.character (preselect.len)
-	if (preselect.len) {
-		for (i in 1:preselect.len) {
-			params[3+i] <- preselect[i]
-		}
-	}
-	if (choices.len) {	# we should hope, the list is not empty...
-		for (i in 1:choices.len) {
-			params[3+preselect.len+i] <- choices[i]
-		}
-	}
+  # serialize all parameters
+  if(!missing(title)){
+    if (is.null (title)) {
+      warning("Deprecated: title = NULL, leave missing if unused!")
+      title <- substitute()
+    }
+  }
+  params[1] <- if(missing (title)) "" else as.character (title)
+  if (multiple) params[2] <- "multi"
+  else params[2] <- "single"
+  params[3] <- as.character (preselect.len)
+  if (preselect.len) {
+    for (i in 1:preselect.len) {
+      params[3+i] <- preselect[i]
+    }
+  }
+  if (choices.len) {	# we should hope, the list is not empty...
+    for (i in 1:choices.len) {
+      params[3+preselect.len+i] <- choices[i]
+    }
+  }
 
-	.rk.do.plain.call ("select.list", params)
+  .rk.do.plain.call ("select.list", params)
 }
 
 # file dialog
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.demo.R b/rkward/rbackend/rpackages/rkward/R/rk.demo.R
index 6dfe4113d..d3b3a813a 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.demo.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.demo.R
@@ -25,6 +25,13 @@
 #' rk.demo("graphics")
 
 "rk.demo" <- function (topic, package, lib.loc=NULL) {
+	# for the time being, translate NULL into missingness and throw a warning
+	if(!missing(package)){
+		if (is.null (package)) {
+			warning("Deprecated: package = NULL, leave missing if unused!")
+			package <- substitute()
+		}
+	}
 	if (missing (package)) {
 		package <- .packages (lib.loc=lib.loc)
 	}
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R
index b247954d2..3e183f998 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R
@@ -52,6 +52,13 @@
 #' @export
 #' @rdname rk.edit
 "rk.edit.files" <- function (name, file="", title, prompt = TRUE) {
+	# for the time being, translate NULL into missingness and throw a warning
+	if(!missing(name)){
+		if (is.null (name)) {
+			warning("Deprecated: name = NULL, leave missing if unused!")
+			name <- substitute()
+		}
+	}
 	if (missing (name)) {
 		name <- character(0)
 	} else {
@@ -73,6 +80,13 @@
 	delete = delete.file  # For compatibility with earlier versions of R
 )
 {
+	# for the time being, translate NULL into missingness and throw a warning
+	if(!missing(title)){
+		if (is.null (title)) {
+			warning("Deprecated: title = NULL, leave missing if unused!")
+			title <- substitute()
+		}
+	}
 	if(missing (title)) title <- character(0)
 	invisible (.Call ("rk.show.files", as.character (file), as.character (header), as.character (title), delete, isTRUE (prompt), PACKAGE="(embedding)"))
 }
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.label-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.label-functions.R
index 4a842c3eb..516558ceb 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.label-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.label-functions.R
@@ -149,6 +149,13 @@
 		else descript[i] <- paste (shortname, " (", lbl, ")", sep="")
 	}
 
+	# for the time being, translate NULL into missingness and throw a warning
+	if(!missing(paste.sep)){
+		if (is.null (paste.sep)) {
+			warning("Deprecated: paste.sep = NULL, leave missing if unused!")
+			paste.sep <- substitute()
+		}
+	}
 	if (missing (paste.sep)) {
 		descript
 	} else {
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
index 948ac6e65..e2a723908 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
@@ -112,6 +112,13 @@
 #' @export
 #' @rdname rk.load.pluginmaps
 "rk.load.pluginmaps" <- function (pluginmap.files, force.add = TRUE, force.reload = TRUE) {
+	# for the time being, translate NULL into missingness and throw a warning
+	if(!missing(pluginmap.files)){
+		if (is.null (pluginmap.files)) {
+			warning("Deprecated: pluginmap.files = NULL, leave missing if unused!")
+			pluginmap.files <- substitute()
+		}
+	}
 	if (missing (pluginmap.files)) pluginmap.files <- character(0)
 	.rk.do.plain.call ("loadPluginMaps", c (ifelse (isTRUE (force.add), "force", "noforce"), ifelse (isTRUE (force.reload), "reload", "noreload"), as.character (pluginmap.files)), synchronous=FALSE)
 }
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.utility-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.utility-functions.R
index 53315a14f..50c28beb9 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.utility-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.utility-functions.R
@@ -124,6 +124,13 @@
 "rk.old.packages" <- function (lib.loc = NULL, repos = getOption("repos"), contriburl = contrib.url(repos, type), instPkgs = installed.packages(lib.loc = lib.loc),
                              method, available, checkBuilt = FALSE, type = getOption("pkgType")) {
 	if (is.null (lib.loc)) lib.loc <- .libPaths ()
+	# for the time being, translate NULL into missingness and throw a warning
+	if(!missing(available)){
+		if (is.null (available)) {
+			warning("Deprecated: available = NULL, leave missing if unused!")
+			available <- substitute()
+		}
+	}
 	if (missing (available)) available <- available.packages (contriburl=contriburl, method=method)
 
 	seen.packages <- character (0)
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.workspace-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.workspace-functions.R
index 6193f6852..9524875a3 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.workspace-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.workspace-functions.R
@@ -40,12 +40,25 @@
 #' @importFrom utils URLdecode
 #' @export
 "rk.save.workplace" <- function (file, description) {
+	# for the time being, translate NULL into missingness and throw a warning
+	if(!missing(file)){
+		if (is.null (file)) {
+			warning("Deprecated: file = NULL, leave missing if unused!")
+			file <- substitute()
+		}
+	}
 	if (missing (file)) {
 		file <- rk.get.workspace.url ()
 		if (is.null(file)) file <- rk.get.tempfile.name (prefix="unsaved", extension=".RData", directory=rk.tempdir ())
 		else file <- URLdecode(file)
 		file <- paste (file, "rkworkplace", sep=".")
 	}
+	if(!missing(description)){
+		if (is.null (description)) {
+			warning("Deprecated: description = NULL, leave missing if unused!")
+			description <- substitute()
+		}
+	}
 	if (missing (description)) lines <- .rk.do.plain.call ("workplace.layout", "get")
 	else lines <- description
 	writeLines (lines, file)
@@ -55,6 +68,13 @@
 #' @importFrom utils URLdecode
 #' @export
 "rk.restore.workplace" <- function (file, close.windows=TRUE) {
+	# for the time being, translate NULL into missingness and throw a warning
+	if(!missing(file)){
+		if (is.null (file)) {
+			warning("Deprecated: file = NULL, leave missing if unused!")
+			file <- substitute()
+		}
+	}
 	if (missing (file)) {
 		if (exists (".rk.workplace.save", envir=globalenv (), inherits=FALSE)) {
 			# For backwards compatibility with workspaces saved by RKWard 0.5.4 and earlier.


More information about the rkward-tracker mailing list