From cd8c7f386b9d352262a2c752f2ba34d710024f3d Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Fri, 19 Jan 2024 09:43:56 -0500 Subject: [PATCH] docs --- R/save_tt.R | 4 +++- man/save_tt.Rd | 6 +++++- vignettes/tutorial.qmd | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/save_tt.R b/R/save_tt.R index 683e9693..92cea4d2 100644 --- a/R/save_tt.R +++ b/R/save_tt.R @@ -3,7 +3,9 @@ #' This function saves an object of class tinytable to a specified file and format, with an option to overwrite existing files. #' #' @param x The tinytable object to be saved. -#' @param output A string representing the path to the file where the object should be saved. The supported file formats are: .html, .png, .md, .pdf, and .tex. +#' @param output String or file path. +#' + If `output` is "markdown", "latex", or "html", the table is returned in a string as an `R` object. +#' + If `output` is a valid file path, the table is saved to file. The supported extensions are: .html, .png, .pdf, .tex and .md (with aliases .txt, .Rmd and .qmd). #' @param overwrite A logical value indicating whether to overwrite an existing file. #' @return invisible(TRUE) #' @export diff --git a/man/save_tt.Rd b/man/save_tt.Rd index 9aa62446..e470e2c5 100644 --- a/man/save_tt.Rd +++ b/man/save_tt.Rd @@ -9,7 +9,11 @@ save_tt(x, output, overwrite = FALSE) \arguments{ \item{x}{The tinytable object to be saved.} -\item{output}{A string representing the path to the file where the object should be saved. The supported file formats are: .html, .png, .md, .pdf, and .tex.} +\item{output}{String or file path. +\itemize{ +\item If \code{output} is "markdown", "latex", or "html", the table is returned in a string as an \code{R} object. +\item If \code{output} is a valid file path, the table is saved to file. The supported extensions are: .html, .png, .pdf, .tex and .md (with aliases .txt, .Rmd and .qmd). +}} \item{overwrite}{A logical value indicating whether to overwrite an existing file.} } diff --git a/vignettes/tutorial.qmd b/vignettes/tutorial.qmd index 5a0b310e..87c2d633 100644 --- a/vignettes/tutorial.qmd +++ b/vignettes/tutorial.qmd @@ -48,16 +48,16 @@ tt(x) ## Output formats -`tinytable` can produce tables in HTML, Markdown, or LaTeX (PDF) format. To choose, we use the `output` argument: +`tinytable` can produce tables in HTML, Markdown, LaTeX, PDF, or PNG format. An appropriate output format form printing is automatically selected based on (1) whether the function is called interactively, (2) is called within RStudio, and (3) based on the output format of the Rmarkdown or Quarto document. Alternatively, users can specify the print format in `print()` or by setting a global option: ```{r} #| eval: false tt(x) |> print("markdown") tt(x) |> print("html") tt(x) |> print("latex") -``` -When calling `tinytable` from a Quarto or Rmarkdown document, `tinytable` detects the output format automatically and generates an HTML or LaTeX table as appropriate. This means that we do not need to explicitly specify the `output` format. +options(tinytable_print_output = "markdown") +``` With the `save_tt()` function, users can also save tables directly to PNG images or PDF documents, or any of the basic formats. All we need to do is supply a valid file name with the appropriate extension (ex: `.png`, `.html`, `.pdf`, etc.): @@ -69,7 +69,7 @@ tt(x) |> save_tt("path/to/file.tex") tt(x) |> save_tt("path/to/file.md") ``` -You can also use `save_tt()` to return a string with the table in it, for further processing in R. In the first case, the table is printed to console with `cat()`. In the second case, it returns as a single string as an `R` object. +`save_tt()` can also return a string with the table in it, for further processing in `R`. In the first case, the table is printed to console with `cat()`. In the second case, it returns as a single string as an `R` object. ```{r} tt(x) |>