Skip to content

Commit

Permalink
Issue #95: plot_tt() can select columns using a regular expression
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 24, 2024
1 parent 4ed94e9 commit bdab1fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/plot_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions inst/tinytest/test-plot_tt.R
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit bdab1fc

Please sign in to comment.