Giter VIP home page Giter VIP logo

r2k's Introduction

Quick Kable Outputs

Dane Van Domelen
[email protected] 2020-04-05

Installation

To install and load r2k from GitHub:

devtools::install_github("vandomed/r2k")
library("r2k")

Concept

The idea is to provide functions that work just like common base R functions, like table and glm, but that immediately produce clean kable printed to the RStudio Viewer or to an R Markdown document.

Each function has two variants: <function>_v and <function>_k. The _v version (for “Viewer”) prints to the Viewer but still returns the object you’d expect from <function>. The _k version (for “kable”) returns a kable which should print nicely without any further steps in R Markdown/knitr documents.

Functions

table_v

If you swap in table_v for table, the results print neatly to the Viewer:

df <- table_v(mtcars$cyl, mtcars$gear)

Figure

From there, if you want to export the table out of R, you could “snip” the table and save it as a figure (as I did for this README) or copy directly from the Viewer and paste outside of R. In my experience, output from the Viewer pastes nicely into Word, Excel, and PowerPoint.

Similarly, you can use table_k in R Markdown documents to quickly generate kable outputs without any extra steps.

r2k

The namesake function is very simple: it just converts R objects to kables by calling kable and kable_styling. To print out the 4-cylinder cars in mtcars, using dplyr and piping:

mtcars %>%
  dplyr::filter(cyl == 4) %>%
  r2k()

Figure

References

Xie, Yihui. 2014. “Knitr: A Comprehensive Tool for Reproducible Research in R.” In Implementing Reproducible Computational Research, edited by Victoria Stodden, Friedrich Leisch, and Roger D. Peng. Chapman; Hall/CRC. http://www.crcpress.com/product/isbn/9781466561595.

———. 2015. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. https://yihui.name/knitr/.

———. 2018. Knitr: A General-Purpose Package for Dynamic Report Generation in R. https://yihui.name/knitr/.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.