Vignettes are long form documentation commonly included in packages. Because they are part of the distribution of the package, they need to be as compact as possible. The html_pretty output format in package prettydoc , an alternative to html_document and html_vignette contained in the rmarkdown package, is able to generate small and nice HTML pages.

Paqueria o liberias

para este protocolo se ulititizaran las paquaterias readr (o readxl) y junitor

  • Readr. es el paquete o liberia que se utiliza para leer una tabal con formatado .csv
  • janitor: Es la liberia que tiene funciones para “limpiar” o modificar las tablas a trabajar

Carga de datos // Inportacion de las tables a trabajar

library(skimr)
## Warning: Paket 'skimr' wurde unter R Version 4.4.1 erstellt

en el siguente recuerdo se utiliza la funcion read_csv para cargar las datos a trabajar,

data("mtcars")

Previsualisazion

head(mtcars, 3)
##                mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4     21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710    22.8   4  108  93 3.85 2.320 18.61  1  1    4    1

head(…x) me permite ver las primeros x numeros, Tail me permite ver las ultimos x columnas

Modificacion del contenido de la tabla

skim(mtcars)
Data summary
Name mtcars
Number of rows 32
Number of columns 11
_______________________
Column type frequency:
numeric 11
________________________
Group variables None

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
mpg 0 1 20.09 6.03 10.40 15.43 19.20 22.80 33.90 ▃▇▅▁▂
cyl 0 1 6.19 1.79 4.00 4.00 6.00 8.00 8.00 ▆▁▃▁▇
disp 0 1 230.72 123.94 71.10 120.83 196.30 326.00 472.00 ▇▃▃▃▂
hp 0 1 146.69 68.56 52.00 96.50 123.00 180.00 335.00 ▇▇▆▃▁
drat 0 1 3.60 0.53 2.76 3.08 3.70 3.92 4.93 ▇▃▇▅▁
wt 0 1 3.22 0.98 1.51 2.58 3.33 3.61 5.42 ▃▃▇▁▂
qsec 0 1 17.85 1.79 14.50 16.89 17.71 18.90 22.90 ▃▇▇▂▁
vs 0 1 0.44 0.50 0.00 0.00 0.00 1.00 1.00 ▇▁▁▁▆
am 0 1 0.41 0.50 0.00 0.00 0.00 1.00 1.00 ▇▁▁▁▆
gear 0 1 3.69 0.74 3.00 3.00 4.00 4.00 5.00 ▇▁▆▁▂
carb 0 1 2.81 1.62 1.00 2.00 2.00 4.00 8.00 ▇▂▅▁▁
mtcars$cyl=as.factor(mtcars$cyl)
mtcars$carb=as.factor(mtcars$carb)
mtcars$vs =as.factor(mtcars$vs)
mtcars$am =as.factor(mtcars$am)
mtcars$gear =as.factor(mtcars$gear)

skim(mtcars)
Data summary
Name mtcars
Number of rows 32
Number of columns 11
_______________________
Column type frequency:
factor 5
numeric 6
________________________
Group variables None

Variable type: factor

skim_variable n_missing complete_rate ordered n_unique top_counts
cyl 0 1 FALSE 3 8: 14, 4: 11, 6: 7
vs 0 1 FALSE 2 0: 18, 1: 14
am 0 1 FALSE 2 0: 19, 1: 13
gear 0 1 FALSE 3 3: 15, 4: 12, 5: 5
carb 0 1 FALSE 6 2: 10, 4: 10, 1: 7, 3: 3

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
mpg 0 1 20.09 6.03 10.40 15.43 19.20 22.80 33.90 ▃▇▅▁▂
disp 0 1 230.72 123.94 71.10 120.83 196.30 326.00 472.00 ▇▃▃▃▂
hp 0 1 146.69 68.56 52.00 96.50 123.00 180.00 335.00 ▇▇▆▃▁
drat 0 1 3.60 0.53 2.76 3.08 3.70 3.92 4.93 ▇▃▇▅▁
wt 0 1 3.22 0.98 1.51 2.58 3.33 3.61 5.42 ▃▃▇▁▂
qsec 0 1 17.85 1.79 14.50 16.89 17.71 18.90 22.90 ▃▇▇▂▁

Styles

Currently html_pretty supports three page themes, cayman (the default), tactile, and architect. And there are also two syntax highlight styles: github to mimic the syntax highlight on Github, and vignette that is used by html_vignette. If no highlight parameter is given, the default style created by Pandoc will be used.

The theme and highlight styles can be given in the document metadata, for example:

output:
  prettydoc::html_pretty:
    theme: cayman
    highlight: github

Happy Knitting!

Feel free to use the knitr infrastructure with dozens of tunable options in your package vignette.

set.seed(123)
n <- 1000
x1  <- matrix(rnorm(n), ncol = 2)
x2  <- matrix(rnorm(n, mean = 3, sd = 1.5), ncol = 2)
x   <- rbind(x1, x2)
head(x)
##             [,1]        [,2]
## [1,] -0.56047565 -0.60189285
## [2,] -0.23017749 -0.99369859
## [3,]  1.55870831  1.02678506
## [4,]  0.07050839  0.75106130
## [5,]  0.12928774 -1.50916654
## [6,]  1.71506499 -0.09514745
smoothScatter(x, xlab = "x1", ylab = "x2")

You can also include code snippets of languages other than R, but note that the block header has no curly brackets around the language name.

// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
    return x * 2;
}

You can write math expressions, e.g. \(Y = X\beta + \epsilon\), footnotes1, and tables, e.g. using knitr::kable().

Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa
4.4 2.9 1.4 0.2 setosa
4.9 3.1 1.5 0.1 setosa

Stay Tuned

Please visit the development page of the prettydoc package for latest updates and news. Comments, bug reports and pull requests are always welcome.


  1. A footnote here.↩︎