Learn R Programming

knitxl (version 0.1.0)

xl_renderer: 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)

# S3 method for default xl_renderer(x, options)

# S3 method for data.frame xl_renderer(x, options)

# S3 method for numeric xl_renderer(x, options)

# S3 method for logical xl_renderer(x, options)

# S3 method for list xl_renderer(x, options)

# S3 method for character xl_renderer(x, options)

Value

A character singleton, a data vector, or a data frame with class knitxl_output_* (either text, vector or data_frame, respectively).

Arguments

x

the object to be rendered in the XLSX file.

options

the knitr and knitxl options used to cutomize the rendering of x

Examples

Run this code
   # 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)

Run the code above in your browser using DataLab