26.1 KnitR Setup
20200602
Packages used in this chapter include diagram (Soetaert 2020), dplyr (Wickham, François, et al. 2022), ggplot2 (Wickham, Chang, et al. 2022), magrittr (Bache and Wickham 2022), xtable (Dahl et al. 2019), Hmisc (Harrell 2022), and rattle (G. Williams 2020).
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: 176,747 × 24
## date location min_temp max_temp rainfall evaporation sunshine
## <date> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2020-02-01 PearceRAAF 13.3 30.1 0 NA 11.8
## 2 2009-07-06 Hobart 5.1 8.6 2 0.6 4.5
## 3 2018-11-26 Perth 9.9 23.2 0 5.6 13.1
## 4 2009-03-22 Brisbane 19.3 28.6 0 6 10.8
## 5 2019-06-26 Mildura 2.8 19.8 0 0.5 8.3
## 6 2010-12-20 Tuggeranong 7 17.6 5.8 NA NA
## 7 2014-10-16 NorahHead 10.4 21.4 1 NA NA
## 8 2015-07-16 Portland 8 11.2 11.4 0.6 4.7
## 9 2008-07-21 Darwin 21.4 32.7 0 5.4 10.9
## 10 2013-04-01 Mildura 10.4 22.5 0 5 9.1
## # … with 176,737 more rows, and 17 more variables: wind_gust_dir <ord>,
## # wind_gust_speed <dbl>, wind_dir_9am <ord>, wind_dir_3pm <ord>,
## # wind_speed_9am <dbl>, wind_speed_3pm <dbl>, humidity_9am <int>,
## # humidity_3pm <int>, pressure_9am <dbl>, pressure_3pm <dbl>,
## # cloud_9am <int>, cloud_3pm <int>, temp_9am <dbl>, temp_3pm <dbl>,
## # rain_today <fct>, risk_mm <dbl>, rain_tomorrow <fct>
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-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0
