From 723ae19b676a0712dbf5727d2b7c9565ee6fd2aa Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Mon, 15 Dec 2025 03:51:39 +0100 Subject: [PATCH 1/3] tinyframe() can now handle formulas without variables (e.g., ~ 1 or ~ 0) --- R/tinyformula.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/tinyformula.R b/R/tinyformula.R index 56fd546e..29189061 100644 --- a/R/tinyformula.R +++ b/R/tinyformula.R @@ -74,6 +74,8 @@ tinyframe = function(formula, data, drop = FALSE) { ## - formula: (sub-)formula ## - data: model.frame from full formula if (is.null(formula)) return(NULL) - names = sapply(attr(terms(formula), "variables")[-1L], deparse, width.cutoff = 500L) + vars = attr(terms(formula), "variables")[-1L] + if (is.null(vars)) return(NULL) + names = sapply(vars, deparse, width.cutoff = 500L) data[, names, drop = drop] } From e4b53d5db54a58fe520dbcecf84f8ccbbc30de9b Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Mon, 15 Dec 2025 03:52:36 +0100 Subject: [PATCH 2/3] support formulas without x-variable such as ~ 0 or ~ 1 or y ~ 1 etc. --- R/tinyplot.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/tinyplot.R b/R/tinyplot.R index 1073a4c9..2cd5ec81 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -1429,13 +1429,15 @@ tinyplot.formula = function( m[[1L]] = quote(stats::model.frame) mf = eval.parent(m) - ## extract x + ## extract x (if any) x = tinyframe(tf$x, mf) xnam = names(x)[[1L]] - if (length(names(x)) != 1L) warning( - paste("formula should specify exactly one x-variable, using:", xnam), + if (!is.null(x)) { + xnam = names(x)[[1L]] + if (length(names(x)) > 1L) warning(paste("formula should specify at most one x-variable, using:", xnam), "\nif you want to use arithmetic operators, make sure to wrap them inside I()") - x = x[[xnam]] + x = x[[xnam]] + } ## extract y (if any) y = tinyframe(tf$y, mf) From 636e832781a9264cb72ab67788ea0a54fa941b5c Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Mon, 15 Dec 2025 04:17:39 +0100 Subject: [PATCH 3/3] handle names(x) only if non-NULL --- R/tinyplot.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/tinyplot.R b/R/tinyplot.R index 2cd5ec81..050b2a61 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -1431,7 +1431,6 @@ tinyplot.formula = function( ## extract x (if any) x = tinyframe(tf$x, mf) - xnam = names(x)[[1L]] if (!is.null(x)) { xnam = names(x)[[1L]] if (length(names(x)) > 1L) warning(paste("formula should specify at most one x-variable, using:", xnam),