Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tinytable support #20

Merged
merged 5 commits into from
Feb 16, 2024
Merged

tinytable support #20

merged 5 commits into from
Feb 16, 2024

Conversation

vincentarelbundock
Copy link
Contributor

@vincentarelbundock vincentarelbundock commented Feb 15, 2024

Hi @dmurdoch,

This is a draft Pull Request to add a new toTinytable() function. Before I spend more time on this function, I wanted to check in to know if this is something you might be interested in. No pressure at all! It's fine if this is out of scope.

tinytable is a new table-drawing package similar to kableExtra. You can read about it here:

https://vincentarelbundock.github.io/tinytable/

It has the following benefits:

  • Zero dependency
  • Highly customizable tables.
  • Simpler and more consistent user interface.
  • Output: LaTeX, HTML, Typst, Word, Markdown, PNG, PDF, Rmarkdown, Quarto
  • Builds tables from scratch instead of using complex regular expressions to modify knitr-produced strings. In my opinion, this makes the code base simpler and easier to debug/maintain/expand.

Below, I copy screenshots of a tabular printed to several different formats. I also paste a GIF to showcase the customizability of tinytable objects.

Let me know what you think.

Examples:

tabular to LaTeX

tables_latex

tabular to HTML

tables_html

tabular to Markdown (pandoc "grid" format)

tables_markdown

tabular to Typst

tables_typst

tabular to Word

tables_docx

tinytable showcase

tinytable_gallery

@vincentarelbundock vincentarelbundock changed the title tinytable support [WIP] tinytable support Feb 15, 2024
@vincentarelbundock vincentarelbundock marked this pull request as draft February 15, 2024 18:27
@vincentarelbundock
Copy link
Contributor Author

---
format: html
---

```{r}
library(tables)
library(tinytable)

f <- Factor(gear) * (mpg + hp + qsec) ~ factor(vs) * (mean + sd) + 1
tab <- tabular(f, data = mtcars)

tab |> toTinytable()
```

@dmurdoch
Copy link
Owner

I'll have to take a look at the code, but the idea of it isn't out of scope, and it's not a huge function that you've written.

@vincentarelbundock
Copy link
Contributor Author

Good to hear.

Justification is missing but should be easy to support.

I'm not sure what options can be passed through options.

@vincentarelbundock
Copy link
Contributor Author

I will ping when a review seems useful. Thanks.

@dmurdoch
Copy link
Owner

dmurdoch commented Feb 15, 2024

Sounds good. Just some notes:

  • it should be a Suggested package, and toTinytable should fail if tinytables can't be loaded.
  • I don't use Roxygen in tables. If you want to use it (and you know how to do so for one file), feel free to do so.
  • I think the only use of options() is the tables.texify option used in several of the functions, e.g. Factor(), etc. There's also a table_options(), booktabs() and htmloptions() functions which have syntax like options(), but which store options locally.

@vincentarelbundock vincentarelbundock changed the title [WIP] tinytable support tinytable support Feb 15, 2024
@vincentarelbundock vincentarelbundock marked this pull request as ready for review February 15, 2024 21:26
@vincentarelbundock
Copy link
Contributor Author

This might be OK now.

I looked at the various options functions and I'm not sure it makes much sense to implement those. It would complicate things, and the whole idea of tinytable is to be output agnostic. I can dive in more if you have specific features you'd like me to implement, but otherwise I'd leave the feature set as is.

I also added a new section to the vignette.

Checks pass and pkgdown website builds on my machine.

@vincentarelbundock
Copy link
Contributor Author

Well, this is embarrassing. The CI failed because I wrote the wrong version number. Latest commit fixes 0.5.0 -> 0.0.5

DESCRIPTION Outdated Show resolved Hide resolved
R/toTinytable.R Outdated Show resolved Hide resolved
man/toTinytable.Rd Outdated Show resolved Hide resolved
man/toTinytable.Rd Outdated Show resolved Hide resolved
@dmurdoch
Copy link
Owner

Somewhere in the comments you asked whether there was a way to mark HTML so it would display automatically. If you have the htmltools package available, you can use browsable(HTML( someHTML )). The HTML() call marks it as HTML so that tags won't be escaped by other functions, and browsable() signals that it should be treated as a web page when displayed.

I think toTinytable is ready to go now, regardless of whether you implement something like the above. Do you agree?

@vincentarelbundock
Copy link
Contributor Author

Thanks. I was able to get it to work with browsable(), but I feel that all those checks and extra functions make the examples section messy and hard to read for people who just call ?toTinytable. I'd vote for keeping this as-is, but can make the change if you want the HTML to display on the website.

Otherwise, yes, I think this is ready to go.

@dmurdoch dmurdoch merged commit 8a8e441 into dmurdoch:master Feb 16, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants