Package 'knitxl'

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

Help Index


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 knitxl(). If NULL, this function will try to guess a default, which will be under the current working directory.

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, parent.frame(), new.env(), or globalenv()).

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)

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 knitr and knitxl options used to cutomize the rendering of x

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)