xl_renderer {knitxl}R Documentation

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)


[Package knitxl version 0.1.0 Index]