knitr::opts_chunk$set(
  collapse = FALSE,
  comment = "#>",
  fig.path = "README-"
)

lifecycle CRAN version GitHub version Last-update Travis-CI Build Status codecov.io


knitr::include_graphics("https://raw.githubusercontent.com/GegznaV/knitrContainer/master/docs/logo.png")

R package knitrContainer

About knitrContainer

knitrContainer is an R package. Its purpose is to collect objects (especially those generated in loops) and print them in knitr -- R Markdown reports.

Why was it created?

Some objects such as pander tables and plotly plots, are not printed from inside loop in a knitr report file in a regular way.knitrContainer solves this problem by providing fuctions to get these objects printed and included in HTML files.

What kind of objects can be collectd and printed with knitrContainer?

An object used by knitrContainer can be any object, that is includable in R list an that is printable, such as :

  1. text;
  2. summaries of data frames;
  3. objects printable with pander;
  4. ggplot2, plotly plots;
  5. etc.

How to install the package?

Install development version from GitHub:

if (!require(devtools)) install.packages("devtools")
library(devtools)
install_github("GegznaV/knitrContainer")

How to use knitrContainer?

Only 4 actions (in short: "CASP") should be done for basic use of knitrContainer package:

  1. Create a container (e.g. use function knitrContainer());
  2. Add objects to the container (use add_as_* family functions, e.g. add_as_is());
  3. Set option results to results='asis' in a chunk of R code in knitr report file;
  4. Print the collected objects appropriately by applying function print_all() in the chunk which has option results='asis'.

Example 1

library(knitrContainer)
# Create
container <- knitrContainer()
# Collect
container <- add_as_text(container, "Text to be added.")
# Print
print_all(container)

Example 2

Example how to add objects using the operator %<>% from package magrittr:

container %<>% add_as_text("Text added using `%<>%` operator.")

It is the same as:

container <- add_as_text(container, "Text added using `<-` operator.")

Type the following code in R to learn more about operator %<>%:

?`%<>%`

More Examples

vignette("v1_examples", package = "knitrContainer")

About Documentation of Development Version

Meaning of symbols in function descriptions:




GegznaV/knitrContainer documentation built on April 16, 2023, 1:38 p.m.