Getting ready for fonts

Notice that the yaml at the beginning of this file includes a latex_enging which will be used when creating a pdf document.

It also includes a mainfont setting called DejaVu Sans. This is not the only font that will work to produce the spark graphs. However, it is a free font available through the extrafont package. If you have not installed extrafont you should do so using the normal package installation procedures. You should then make sure that the desired font is installed.

The code below will not run automatically when you knit, instead you should run it in tbe console.

install.packages(c("extrafont"))
font_install("DejaVu Sans")

If there are any difficulties please read the extrafont documentation.

library(pander)
library(knitr)
library(skimr)

Try knitting this document to PDF, HTML, doc or any other format you wish to try. You will notice that there are slight differences between them.

Plain printing

The first example shows what printing the basic skim function looks like. You can try knitting to different formats to see how it changes.

skim(iris)
## Skim summary statistics
##  n obs: 150 
##  n variables: 5 
## 
## Variable type: factor 
##   variable missing complete   n n_unique                       top_counts
## 1  Species       0      150 150        3 set: 50, ver: 50, vir: 50, NA: 0
##   ordered
## 1   FALSE
## 
## Variable type: numeric 
##       variable missing complete   n mean   sd min p25 median p75 max
## 1 Petal.Length       0      150 150 3.76 1.77 1   1.6   4.35 5.1 6.9
## 2  Petal.Width       0      150 150 1.2  0.76 0.1 0.3   1.3  1.8 2.5
## 3 Sepal.Length       0      150 150 5.84 0.83 4.3 5.1   5.8  6.4 7.9
## 4  Sepal.Width       0      150 150 3.06 0.44 2   2.8   3    3.3 4.4
##       hist
## 1 ▇▁▁▂▅▅▃▁
## 2 ▇▁▁▅▃▃▂▂
## 3 ▂▇▅▇▆▅▂▂
## 4 ▁▂▅▇▃▂▁▁

It is possible that the histograms will not print in all of the formats.

Kable example

Kable is a function from the knitr package that provides formatting of tables. To use kable() you should add results='asis' as a code chunk option.

skim(iris) %>% kable()

Skim summary statistics
n obs: 150
n variables: 5

Variable type: factor

variable missing complete n n_unique top_counts ordered
Species 0 150 150 3 set: 50, ver: 50, vir: 50, NA: 0 FALSE

Variable type: numeric

variable missing complete n mean sd min p25 median p75 max hist
Petal.Length 0 150 150 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▁▂▅▅▃▁
Petal.Width 0 150 150 1.2 0.76 0.1 0.3 1.3 1.8 2.5 ▇▁▁▅▃▃▂▂
Sepal.Length 0 150 150 5.84 0.83 4.3 5.1 5.8 6.4 7.9 ▂▇▅▇▆▅▂▂
Sepal.Width 0 150 150 3.06 0.44 2 2.8 3 3.3 4.4 ▁▂▅▇▃▂▁▁

Pander example

Pander is a package that provides advanced formatting for tables. There are two formats for pander, results='asis' and results='markdown'. Markdown will display in the same way as the results show in the console. You may prefer this layout in the console to the default layout.

panderOptions('knitr.auto.asis', FALSE)
skim(iris) %>% pander()
## Skim summary statistics  
##    n obs: 150    
##  n variables: 5    
## 
## ------------------------------------------------
##  variable   missing   complete    n    n_unique 
## ---------- --------- ---------- ----- ----------
##  Species       0        150      150      3     
## ------------------------------------------------
## 
## Table: Table continues below
## 
##  
## ------------------------------------------
##            top_counts             ordered 
## -------------------------------- ---------
##  set: 50, ver: 50, vir: 50, NA:    FALSE  
##                0                          
## ------------------------------------------
## 
## 
## ----------------------------------------------------------------------------
##    variable     missing   complete    n    mean    sd    min   p25   median 
## -------------- --------- ---------- ----- ------ ------ ----- ----- --------
##  Petal.Length      0        150      150   3.76   1.77    1    1.6    4.35  
## 
##  Petal.Width       0        150      150   1.2    0.76   0.1   0.3    1.3   
## 
##  Sepal.Length      0        150      150   5.84   0.83   4.3   5.1    5.8   
## 
##  Sepal.Width       0        150      150   3.06   0.44    2    2.8     3    
## ----------------------------------------------------------------------------
## 
## Table: Table continues below
## 
##  
## ----------------------
##  p75   max     hist   
## ----- ----- ----------
##  5.1   6.9   ▇▁▁▂▅▅▃▁ 
## 
##  1.8   2.5   ▇▁▁▅▃▃▂▂ 
## 
##  6.4   7.9   ▂▇▅▇▆▅▂▂ 
## 
##  3.3   4.4   ▁▂▅▇▃▂▁▁ 
## ----------------------

In this case it may be that the histograms do not print in PDFs or another format (even though the histograms may display in the console when using the same code). This is because the basic font for “as is” in PDf does not includ building blocks

The code chunk options can be changed to use asis (results='asis'). However because of an issue in pandoc the subheadings showing the types for the separte tables will not display

skim(iris) %>% pander()

Skim summary statistics
n obs: 150
n variables: 5

Table continues below
variable missing complete n n_unique
Species 0 150 150 3
top_counts ordered
set: 50, ver: 50, vir: 50, NA: 0 FALSE
Table continues below
variable missing complete n mean sd min p25 median
Petal.Length 0 150 150 3.76 1.77 1 1.6 4.35
Petal.Width 0 150 150 1.2 0.76 0.1 0.3 1.3
Sepal.Length 0 150 150 5.84 0.83 4.3 5.1 5.8
Sepal.Width 0 150 150 3.06 0.44 2 2.8 3
p75 max hist
5.1 6.9 ▇▁▁▂▅▅▃▁
1.8 2.5 ▇▁▁▅▃▃▂▂
6.4 7.9 ▂▇▅▇▆▅▂▂
3.3 4.4 ▁▂▅▇▃▂▁▁