Type: | Package |
Title: | Generates a Spreadsheet Report from an 'rmarkdown' File |
Version: | 0.1.0 |
Description: | Convert an R Markdown documents into an '.xlsx' spreadsheet reports with the knitxl() function, which works similarly to knit() from the 'knitr' package. The generated report can be opened in 'Excel' or similar software for further analysis and presentation. |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
Depends: | knitr (≥ 1.39) |
Imports: | commonmark (≥ 1.8.0), glue (≥ 1.6.2), magrittr (≥ 2.0.3), openxlsx (≥ 4.2.5), purrr (≥ 0.3.4), R6 (≥ 2.5.1), readbitmap (≥ 0.1.5), readr (≥ 2.1.2), stringr (≥ 1.4.0), xml2 (≥ 1.3.3), yaml (≥ 2.3.7) |
Suggests: | testthat (≥ 3.0.0), waldo (≥ 0.4.0) |
Config/testthat/edition: | 3 |
RoxygenNote: | 7.2.3 |
URL: | https://github.com/dreanod/knitxl |
BugReports: | https://github.com/dreanod/knitxl/issues |
NeedsCompilation: | no |
Packaged: | 2023-04-15 07:37:48 UTC; denisdreano |
Author: | Denis Dreano [cre, aut, cph] |
Maintainer: | Denis Dreano <denis.dreano@protonmail.ch> |
Repository: | CRAN |
Date/Publication: | 2023-04-18 13:40:02 UTC |
Knit a Document to an XLSX file
Description
This function takes an input file, extracts the R code in it according to a list of patterns, evaluates the code and writes the output in an XLSX spreadsheet file.
Usage
knitxl(
input,
output = NULL,
text = NULL,
quiet = FALSE,
envir = parent.frame(),
encoding = "UTF-8"
)
Arguments
input |
Path to the input file. |
output |
Path to the output file for |
text |
A character vector. This is an alternative way to provide the input file. |
quiet |
Boolean; suppress the progress bar and messages? |
envir |
Environment in which code chunks are to be evaluated, for
example, |
encoding |
Encoding of the input file; always assumed to be UTF-8 (i.e., this argument is effectively ignored). |
Value
The compiled document is written into the output file, and the path of the output file is returned invisibly.
Examples
library(knitxl)
path_to_input <- system.file("examples", "knitxl-minimal.Rmd", package = "knitxl")
path_to_output <- "knitxl-minimal.xlsx"
knitxl(path_to_input, output = path_to_output) # will generate knitxl-minimal.xlsx
unlink(path_to_output)
Extend knitr::sew()
generic to write text, vectors and data table to the
output .xlsx file.
Description
These functions are called within knitr::knit()
to write either text
vector or a table into the output .xlsx file produced by knitxl()
.
Usage
## S3 method for class 'knitxl_output_text'
sew(x, options, ...)
## S3 method for class 'knitxl_output_vector'
sew(x, options, ...)
## S3 method for class 'knitxl_output_data_frame'
sew(x, options, ...)
Arguments
x |
Output from evaluate::evaluate(). |
options |
A list of chunk options used to control output. |
... |
Other arguments to pass to methods. |
Value
Invisibly returns NULL
.
Represents an R object into a format that can be printed into an XLSX file
Description
This is a generic function that is intended for developers who want
to extend knitxl
to print new classes R objects. It transforms an object
into a knitxl_output_*
class (either text
, vector
or data_frame
)
that can be printed in an XLSX file.
Usage
xl_renderer(x, options)
## Default S3 method:
xl_renderer(x, options)
## S3 method for class 'data.frame'
xl_renderer(x, options)
## S3 method for class 'numeric'
xl_renderer(x, options)
## S3 method for class 'logical'
xl_renderer(x, options)
## S3 method for class 'list'
xl_renderer(x, options)
## S3 method for class 'character'
xl_renderer(x, options)
Arguments
x |
the object to be rendered in the XLSX file. |
options |
the |
Value
A character singleton, a data vector, or a data frame with class
knitxl_output_*
(either text
, vector
or data_frame
, respectively).
Examples
# Writes the summary of linear model fits a print output:
xl_renderer.lm <- function(x, options) {
res <- capture.output(summary(x))
res <- paste0(res, collapse = "\n")
class(res) <- "knit_xl_output_vector"
res
}
registerS3method("xl_renderer", "lm", xl_renderer.lm)
# knitxl will now print the summary of `lm` object in the generated
# .xlsx file.
# This will instead write the summary information about the coefficients
# in a table:
xl_renderer.lm <- function(x, options) {
summary(x)$coefficients %>%
as.data.frame() %>%
new_knitxl_output_data_frame()
}
registerS3method("xl_renderer", "lm", xl_renderer.lm)