28.1 KnitR Setup
20200602
Packages used in this chapter include diagram (Soetaert 2020), dplyr (Wickham, François, et al. 2023), ggplot2 (Wickham, Chang, et al. 2023), magrittr (Bache and Wickham 2022), xtable (Dahl et al. 2019), Hmisc (Harrell 2023), and rattle (G. Williams 2023).
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.
<- "weatherAUS"
dsname <- get(dsname)
ds
<- nrow(ds)
nobs
<- names(ds)
vnames %<>% clean_names(numerals="right")
ds names(vnames) <- names(ds)
<- names(ds)
vars <- "rain_tomorrow"
target <- c(target, vars) %>% unique() %>% rev() vars
A random sample of the dataset:
%>% sample_frac() ds
## # A tibble: 226,868 × 24
## date location min_temp max_temp rainfall evaporation sunshine
## <date> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2014-08-01 GoldCoast 13.8 25.5 0 NA NA
## 2 2018-10-27 AliceSprings 19.2 26.8 1.4 NA NA
## 3 2015-02-15 PearceRAAF 14.2 31.9 0 NA 12.6
## 4 2020-07-22 MountGambier 6.7 12.5 0 NA NA
## 5 2015-08-24 PerthAirport 9.5 19 0 1.4 10.5
## 6 2021-12-29 Townsville 22.9 25.9 3.4 NA NA
## 7 2018-08-16 MelbourneAirport 4.6 14.6 0 4.8 7.5
....
References
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