Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]])
}
}

Expand Down
71 changes: 71 additions & 0 deletions inst/tinytest/_tinysnapshot/tinyplot_do_call.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion inst/tinytest/test-tinyplot_add.R
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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")
expect_snapshot_plot(f, label = "tinyplot_add_no_recursive_margins")