diff --git a/R/plot_tt.R b/R/plot_tt.R index c8475420..f82ee4aa 100644 --- a/R/plot_tt.R +++ b/R/plot_tt.R @@ -38,15 +38,22 @@ plot_tt <- function(x, assets = "tinytable_assets", ...) { + out <- x + + # j is a regular expression + # before assertions + if (is.character(j) && !is.null(meta(x, "colnames"))) { + j <- grep(j, meta(x, "colnames"), perl = TRUE) + } + assert_integerish(i, null.ok = TRUE) assert_integerish(j, null.ok = TRUE) assert_numeric(height, len = 1, lower = 0) assert_numeric(asp, len = 1, lower = 0, upper = 1) assert_class(x, "tinytable") - out <- x - ival <- if (is.null(i)) seq_len(meta(x, "nrows")) else i jval <- if (is.null(j)) seq_len(meta(x, "ncols")) else j + ival <- if (is.null(i)) seq_len(meta(x, "nrows")) else i len <- length(ival) * length(jval) diff --git a/inst/tinytest/test-plot_tt.R b/inst/tinytest/test-plot_tt.R new file mode 100644 index 00000000..00f83a24 --- /dev/null +++ b/inst/tinytest/test-plot_tt.R @@ -0,0 +1,5 @@ +# issue #95: plot_tt() can select j with a regex +tab <- data.frame(a = 1, b = 2) |> + tt() |> + plot_tt(1, j = "a", fun = "density", data = list(rnorm(100))) +expect_inherits(tab, "tinytable") \ No newline at end of file