Skip to content

Commit

Permalink
Merge branch 'main' into tabularray_inner_end
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Dec 13, 2024
2 parents 8d6f64f + d462e19 commit 9cdd742
Show file tree
Hide file tree
Showing 146 changed files with 3,653 additions and 2,821 deletions.
3 changes: 1 addition & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ README.qmd
man-roxygen
Makefile
.quarto
vignettes/.*\.qmd$
vignettes/.*\.bib$
vignettes/
docs/
docs
.github
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: tinytable
Type: Package
Title: Simple and Configurable Tables in 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', and 'Typst' Formats
Description: Create highly customized tables with this simple and dependency-free package. Data frames can be converted to 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', or 'Typst' tables. The user interface is minimalist and easy to learn. The syntax is concise. 'HTML' tables can be customized using the flexible 'Bootstrap' framework, and 'LaTeX' code with the 'tabularray' package.
Version: 0.6.1
Version: 0.6.1.4
Imports:
methods
Depends:
Expand Down Expand Up @@ -31,8 +31,8 @@ Suggests:
URL: https://vincentarelbundock.github.io/tinytable/
BugReports: https://github.com/vincentarelbundock/tinytable/issues
Authors@R: c(
person("Vincent", "Arel-Bundock",
email = "[email protected]",
person("Vincent", "Arel-Bundock",
email = "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2042-7063")))
License: GPL (>= 3)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(knitr::knit_print, tinytable)
S3method(print,tinytable)
export(format_tt)
export(group_tt)
Expand Down
28 changes: 23 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# News

## Development

Breaking change:

* `format_tt()` is now stricter, applying no formatting at all by default. Users must specify an argument explicitly or set a global option to change the table.

Bugs:

* `save_tt("file.pdf")` works with colors. Thanks to @olivedv for the report and solution #395.

New:

* `style_tt("notes")` and `style_tt("caption")` can style footnotes and captions. Note: This will only style captions handled by the `caption` argument in `tt()`, and not captions created by Quarto.

Misc:

* Documentation improvements

## 0.6.1

* Bug fix: d-column LaTeX generated an error in some cases.
Expand Down Expand Up @@ -83,7 +101,7 @@ MathJax = {
* `format_tt(num_big_mark)` applies to integer columns.
* Use `getOption("viewer")` instead of `rstudioapi::viewer()` for positron support
* `glue::glue()` string is accepted by `format_tt()`. Thanks to @LukasWallrich for report #792 on the `modelsummary` repository.
* Support Github Flavored Markdown (`gfm`) output. Thanks to @kylebutts for contribution #315.
* Support Github Flavored Markdown (`gfm`) output. Thanks to @kylebutts for contribution #315.
* `theme_tt("rotate")` to rotate tables in LaTeX or Typst.
* `save_tt("/path/to/file")` returns the file path invisibly. Thanks to @yjunechoe for issue #328.

Expand Down Expand Up @@ -188,7 +206,7 @@ New features:

* `rbind()` and `rbind2()` can be used to stack `tinytable` objects. `rbind2()` is more flexible than `rbind()`. See `?tinytable::rbind2`
* New output format in `print()`: "dataframe"
* Rename table headers: `colnames(tab) <- c("a", "b", "c")`
* Rename table headers: `colnames(tab) <- c("a", "b", "c")`
* `theme_tt("resize")` gets a `direction` argument with "up", "down", "both" options. Thanks to @MarcoPortmann for feature request #207

Minor:
Expand All @@ -207,7 +225,7 @@ New function `theme_tt()`:

* Function to apply collections of transformations to a `tinytable`.
* Visual themes:
- grid, void, striped, bootstrap, default
- grid, void, striped, bootstrap, default
* `resize`: Insert a LaTeX table in a `resizebox` environment to ensure a table fits the page, or to scale it to a fraction of `\linewidth`
* `placement`: Determine where a LaTeX table float is positioned. Ex: `[H]`, `[htbp]`
* `multipage`: Split long LaTeX tables across multiple pages with (optional) repeated headers/footers. Uses the `longtblr` environment from `tabularray`.
Expand Down Expand Up @@ -275,7 +293,7 @@ Bugfix:

New:

- `Typst` tables are now supported using the `tablex` extension:
- `Typst` tables are now supported using the `tablex` extension:
- https://typst.app/
- https://github.com/PgBiel/typst-tablex
- `escape` argument in `format_tt()` escapes or substitutes special characters in LaTeX or HTML output to prevent compilation and rendering errors.
Expand Down Expand Up @@ -306,7 +324,7 @@ Bug fixes:

Documentation:

- Improved vignette on the package website.
- Improved vignette on the package website.
- Various documentation updates.
- Math in $$ is the new recommendation.

Expand Down
4 changes: 4 additions & 0 deletions R/build_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ build_tt <- function(x, output = NULL) {

x@output <- output

# apply the style_notes
x <- style_notes(x)
x <- style_caption(x)

for (th in x@lazy_theme) {
fn <- th[[1]]
args <- th[[2]]
Expand Down
174 changes: 93 additions & 81 deletions R/class.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,50 @@ swap_class <- function(x, new_class) {
setClassUnion("NULLorCharacter", c("NULL", "character"))

#' tinytable S4 class
#'
#'
#' @keywords internal
#' @export
setClass(
Class = "tinytable",
slots = representation(
table_dataframe = "data.frame",
table_string = "character",
data = "data.frame",
caption = "character",
width = "numeric",
width_cols = "numeric",
notes = "list",
theme = "list",
placement = "character",
body = "character",
nrow = "numeric",
ncol = "numeric",
nhead = "numeric",
ngroupi = "numeric",
ngroupj = "numeric",
group_i_idx = "numeric",
names = "NULLorCharacter",
output = "character",
output_dir = "character",
id = "character",
bootstrap_class = "character",
bootstrap_css_rule = "character",
css = "data.frame",
style = "data.frame",
lazy_format = "list",
lazy_group = "list",
lazy_style = "list",
lazy_plot = "list",
lazy_finalize = "list",
lazy_theme = "list",
portable = "logical"
)
Class = "tinytable",
slots = representation(
table_dataframe = "data.frame",
table_string = "character",
data = "data.frame",
caption = "character",
width = "numeric",
width_cols = "numeric",
notes = "list",
theme = "list",
placement = "character",
body = "character",
nrow = "numeric",
ncol = "numeric",
nhead = "numeric",
ngroupi = "numeric",
ngroupj = "numeric",
group_i_idx = "numeric",
names = "NULLorCharacter",
output = "character",
output_dir = "character",
id = "character",
bootstrap_class = "character",
bootstrap_css_rule = "character",
css = "data.frame",
style = "data.frame",
style_caption = "list",
style_notes = "list",
lazy_format = "list",
lazy_group = "list",
lazy_style = "list",
lazy_plot = "list",
lazy_finalize = "list",
lazy_theme = "list",
portable = "logical"
)
)

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("initialize", "tinytable", function(
Expand Down Expand Up @@ -95,85 +97,97 @@ setMethod("initialize", "tinytable", function(
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("nrow", "tinytable", function(x) return(x@nrow))
setMethod("nrow", "tinytable", function(x) {
return(x@nrow)
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("ncol", "tinytable", function(x) return(x@ncol))
setMethod("ncol", "tinytable", function(x) {
return(x@ncol)
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
#' @export
setMethod("colnames", "tinytable", function(x) return(x@names))
setMethod("colnames", "tinytable", function(x) {
return(x@names)
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
#' @export
setMethod("names", "tinytable", function(x) return(x@names))
setMethod("names", "tinytable", function(x) {
return(x@names)
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
#' @export
setReplaceMethod("colnames",
signature = "tinytable",
definition = function(x, value) {
# Issue #306
if (length(value) == 0) value <- NULL
if (!is.null(value)) {
assert_character(value, len = length(x@names))
} else {
if (x@nhead == 1) x@nhead <- 0
}
x@names <- value
return(x)
}
signature = "tinytable",
definition = function(x, value) {
# Issue #306
if (length(value) == 0) value <- NULL
if (!is.null(value)) {
assert_character(value, len = length(x@names))
} else {
if (x@nhead == 1) x@nhead <- 0
}
x@names <- value
return(x)
}
)

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
#' @export
setReplaceMethod("names",
signature = "tinytable",
definition = function(x, value) {
# Issue #306
if (length(value) == 0) value <- NULL
if (!is.null(value)) {
assert_character(value, len = length(x@names))
} else {
if (x@nhead == 1) x@nhead <- 0
}
x@names <- value
return(x)
}
signature = "tinytable",
definition = function(x, value) {
# Issue #306
if (length(value) == 0) value <- NULL
if (!is.null(value)) {
assert_character(value, len = length(x@names))
} else {
if (x@nhead == 1) x@nhead <- 0
}
x@names <- value
return(x)
}
)

#' Dimensions a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("dim", "tinytable", function(x) return(c(x@nrow, x@ncol)))
setMethod("dim", "tinytable", function(x) {
return(c(x@nrow, x@ncol))
})

#' Column names of a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("names", "tinytable", function(x) return(x@names))
setMethod("names", "tinytable", function(x) {
return(x@names)
})

#' Convert a tinytable S4 object to a string
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("as.character", "tinytable", function(x) {
Expand All @@ -188,7 +202,7 @@ setClass("tinytable_grid", contains = "tinytable")
setClass("tinytable_dataframe", contains = "tinytable")

#' Apply style settings to a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setGeneric(
Expand All @@ -197,7 +211,7 @@ setGeneric(
)

#' Apply group settings to a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setGeneric(
Expand All @@ -206,7 +220,7 @@ setGeneric(
)

#' Apply group settings to a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setGeneric(
Expand All @@ -215,12 +229,10 @@ setGeneric(
)

#' Apply final settings to a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setGeneric(
name = "finalize",
def = function(x, ...) standardGeneric("finalize")
)


Loading

0 comments on commit 9cdd742

Please sign in to comment.