Skip to content

Commit

Permalink
fixup: format_tt j cannot be NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Feb 3, 2024
1 parent 0b93c66 commit 619b4c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions R/format_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ format_tt_lazy <- function(x,
assert_flag(markdown)
j <- sanitize_j(j, x)

# In sanity_tt(), we fill in missing NULL `j` in the format-specific versions,
# because tabularray can do whole column styling. Here, we need to fill in
# NULL for all formats since this is applied before creating the table.
if (is.null(j)) j <- seq_len(ncol(x))

# format each column
for (col in j) {
# sprintf() is self-contained
Expand Down
10 changes: 9 additions & 1 deletion vignettes/tutorial.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,20 @@ We can style entire columns by omitting the `i` argument:
tt(x) |> style_tt(j = c(2, 4), bold = TRUE)
```

The `j` argument accepts integer vectors, but also a string with a Perl-style regular expression, which makes it easier to select columns by name:
The `j` argument accepts integer vectors, character vectors, but also a string with a Perl-style regular expression, which makes it easier to select columns by name:

```{r}
tt(x) |> style_tt(j = c("mpg", "drat"), color = "orange")
tt(x) |> style_tt(j = "mpg|drat", color = "orange")
```

Here we use a "negative lookahead" to exclude certain columns:

```{r}
tt(x) |> style_tt(j = "^(?!drat|mpg)", color = "orange")
```

Of course, we can also call the `style_tt()` function several times to apply different styles to different parts of the table:

```{r}
Expand Down

0 comments on commit 619b4c4

Please sign in to comment.