From 5dbe61c858a7cdf55472ef34a2381aa79fd59734 Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Tue, 7 Oct 2025 01:33:57 +0200 Subject: [PATCH 1/3] .last_call of tinyplot is now determined based on the last call of a function equivalent to the tinyplot() generic as this also works with do.call() --- R/tinyplot.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/tinyplot.R b/R/tinyplot.R index 597b8f05..6f0da3eb 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -652,10 +652,10 @@ tinyplot.default = function( assert_logical(add) if (!add) { calls = sys.calls() - tinyplot_calls = "(^tinyplot$)|(^tinyplot::tinyplot$)|(^plt$)|(^tinyplot::plt)|(^tinyplot:::)" - idx = grep(tinyplot_calls, sapply(calls, function(k) k[[1]])) + is_tinyplot_call <- function(x) identical(tinyplot, try(eval(x[[1L]]), silent = TRUE)) + idx = which(vapply(calls, is_tinyplot_call, FALSE)) if (length(idx) > 0) { - set_environment_variable(.last_call = calls[[idx[1]]]) + set_environment_variable(.last_call = calls[[idx[1L]]]) } } From 5e19f9b05e5b17e7680439fbbfc90d6b324fecb3 Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Tue, 7 Oct 2025 01:48:33 +0200 Subject: [PATCH 2/3] add NEWS item for .last_call fix --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index d1863e24..9853f112 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,10 @@ where the formatting is also better._ - `type_text()` now defaults to displaying `y` values if an explicit `labels` arg is not provided, mirroring the behaviour of the base `text()` function. (#501 @grantmcdermott) +- Determining the last call of the `tinyplot()` generic in preparation for + `tinyplot_add()` is now more robust so that it is compatible with `do.call()` + again (reported by @FlorianSchwendinger). This is achieved by inspecting + the functions called rather than just their names. (#504 @zeileis) ### Documentation From 719fcc4234362693425f7b503ec5a0b8534b6185 Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Tue, 7 Oct 2025 01:53:21 +0200 Subject: [PATCH 3/3] test case for using tinyplot_add() after do.call(tinyplot) --- .../_tinysnapshot/tinyplot_do_call.svg | 71 +++++++++++++++++++ inst/tinytest/test-tinyplot_add.R | 11 ++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 inst/tinytest/_tinysnapshot/tinyplot_do_call.svg diff --git a/inst/tinytest/_tinysnapshot/tinyplot_do_call.svg b/inst/tinytest/_tinysnapshot/tinyplot_do_call.svg new file mode 100644 index 00000000..0da06841 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/tinyplot_do_call.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + +x +y + + + + + + +1 +2 +3 +4 +5 + + + + + +-1.0 +-0.5 +0.0 +0.5 + + + + + + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/test-tinyplot_add.R b/inst/tinytest/test-tinyplot_add.R index 1ee292c9..af2a4305 100644 --- a/inst/tinytest/test-tinyplot_add.R +++ b/inst/tinytest/test-tinyplot_add.R @@ -75,6 +75,15 @@ f = function() { expect_snapshot_plot(f, label = "tinyplot_lollipop") +# use tinyplot_add() after do.call(tinyplot) +f = function() { + d = data.frame(x = 1:5, y = sin(1:5)) + do.call(tinyplot, list(y ~ x, data = d)) + do.call(tinyplot_add, list(type = "h")) +} +expect_snapshot_plot(f, label = "tinyplot_do_call") + + # check that we are avoiding recursive margins for facets, by properly restoring # the original state f = function() { @@ -83,4 +92,4 @@ f = function() { tinyplot(Sepal.Width ~ Sepal.Length, facet = ~Species, data = iris) tinyplot_add(type = "lm") } -expect_snapshot_plot(f, label = "tinyplot_add_no_recursive_margins") \ No newline at end of file +expect_snapshot_plot(f, label = "tinyplot_add_no_recursive_margins")