knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The primary of the pdfr
package is to save you, the time-limited user, from having to type 12 (yes, 12!) extra characters when printing out full data frames. Intruiged? Read on...
This mostly comes in handy when trying to view the entire data frame (or more likely, tibble) being piped through a tidyverse
pipeline. One of the generally intelligent decisions that tibble
makes is to only print the first several columns, and first several rows, to save your eyeballs from scrolling:
library(ggplot2) #> contains example data set library(dplyr) #> allows demo of piping library(tibble) #> show demo with tibbles msleep.tib <- as.tibble(msleep) msleep.tib %>% filter(vore == "omni")
In this case, however, you can't actually see all the columns. Sometimes, it is actually desirable to view the entire output.
On one hand, this sort of problem can be solved by setting tibble options, e.g. options(tibble.print_max = Inf)
. But maybe you can't remember to type this line, or maybe you only sometimes want to print the whole data.
In those circumstances, you'll often find yourself piping into print.data.frame()
:
msleep.tib %>% filter(vore == "omni") %>% print.data.frame()
That's all well and good, but 16 characters?! How can lazy programmers like you and me cope with this undue burden? Finally, the answer has arrived - you will find salvation in the pdfr()
package:
library(pdfr) #> Hurray, only 4 characters! msleep.tib %>% filter(vore == "omni") %>% pdfr()
Now that felt much better. Phew.
There are also two other useful functions, hpdfr()
and tpdfr()
which will print the head or tail, respectively, of the full data frame. Below are examples of using hpdfr()
, and tpdfr()
works in the same way.
#> Print the full head msleep.tib %>% filter(vore == "omni") %>% hpdfr() #> Print first 2 rows with the extra argument to hpdfr() msleep.tib %>% filter(vore == "omni") %>% hpdfr(2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.