28.1 KnitR Setup
20200602
Packages used in this chapter include diagram (Soetaert 2020), dplyr (Wickham et al. 2023), ggplot2 (Wickham et al. 2024), magrittr (Bache and Wickham 2022), xtable (Dahl et al. 2019), Hmisc (Harrell 2024), and rattle (G. Williams 2022).
Packages are loaded into the currently running R session from your
local library directories on disk. Missing packages can be installed
using utils::install.packages() within R. On Ubuntu, for
example, R packages can also be installed using $ wajig install r-cran-<pkgname>
.
# Load required packages from local library into the R session.
library(rattle) # Dataset: weatherAUS.
library(magrittr) # Data pipelines: %>% %T>% %<>%.
library(ggplot2) # Visualise data.
library(xtable) # Format R data frames as LaTeX tables.
library(Hmisc) # Escape special LaTeX charaters.
library(diagram) # Produce a flowchart.
library(dplyr) # Data wrangling.
library(scales)
library(knitr)
The rattle::weatherAUS dataset is loaded into the template
variable ds
and further template variables are setup as
introduced by Graham J. Williams (2017). See
Chapter 8 for details.
dsname <- "weatherAUS"
ds <- get(dsname)
nobs <- nrow(ds)
vnames <- names(ds)
ds %<>% clean_names(numerals="right")
names(vnames) <- names(ds)
vars <- names(ds)
target <- "rain_tomorrow"
vars <- c(target, vars) %>% unique() %>% rev()
A random sample of the dataset:
## # A tibble: 208,495 × 24
## date location min_temp max_temp rainfall evaporation sunshine
## <date> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2010-10-25 MountGambier 1.2 20.2 0 2 12.4
## 2 2018-11-29 SalmonGums 11.3 24.8 0 NA NA
## 3 2018-03-09 Albany 18.1 21.8 0 4 NA
## 4 2020-07-05 Walpole 14 16.9 0 NA NA
## 5 2019-08-19 Nuriootpa -0.3 11.5 4.8 4.8 7.6
## 6 2014-10-13 Mildura 9.7 19.4 0 11.8 11.8
## 7 2013-01-23 Sale 13.1 24 0 6.8 8.7
....
References
Bache, Stefan Milton, and Hadley Wickham. 2022. Magrittr: A Forward-Pipe Operator for r. https://magrittr.tidyverse.org.
Dahl, David B., David Scott, Charles Roosen, Arni Magnusson, and Jonathan Swinton. 2019. Xtable: Export Tables to LaTeX or HTML. http://xtable.r-forge.r-project.org/.
Harrell, Frank E, Jr. 2024. Hmisc: Harrell Miscellaneous. https://hbiostat.org/R/Hmisc/.
Soetaert, Karline. 2020. Diagram: Functions for Visualising Simple Graphs (Networks), Plotting Flow Diagrams. https://CRAN.R-project.org/package=diagram.
Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, Dewey Dunnington, and Teun van den Brand. 2024. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://ggplot2.tidyverse.org.
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. Dplyr: A Grammar of Data Manipulation. https://dplyr.tidyverse.org.
Williams, Graham. 2022. Rattle: Graphical User Interface for Data Science in r. https://rattle.togaware.com/.
Williams, Graham J. 2017. The Essentials of Data Science: Knowledge Discovery Using r. The r Series. CRC Press.
Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0