Title: | Generates a Spreadsheet Report from an 'rmarkdown' File |
---|---|
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. |
Authors: | Denis Dreano [cre, aut, cph] |
Maintainer: | Denis Dreano <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.0 |
Built: | 2024-11-09 03:21:50 UTC |
Source: | https://github.com/dreanod/knitxl |
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.
knitxl( input, output = NULL, text = NULL, quiet = FALSE, envir = parent.frame(), encoding = "UTF-8" )
knitxl( input, output = NULL, text = NULL, quiet = FALSE, envir = parent.frame(), encoding = "UTF-8" )
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). |
The compiled document is written into the output file, and the path of the output file is returned invisibly.
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)
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)
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.
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)
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)
x |
the object to be rendered in the XLSX file. |
options |
the |
A character singleton, a data vector, or a data frame with class
knitxl_output_*
(either text
, vector
or data_frame
, respectively).
# 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)
# 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)