6.1 Strings Setup

20180720 Packages used in this chapter include dplyr (Wickham, François, et al. 2023), glue (Hester and Bryan 2022), magrittr (Bache and Wickham 2022), readr (Wickham, Hester, and Bryan 2023), stringr (Wickham 2022b), stringi (Gagolewski et al. 2023), scales (Wickham and Seidel 2022), 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(dplyr)        # Wrangling: mutate().
library(stringi)      # The string concat operator %s+%.
library(stringr)      # String manipulation.
library(glue)         # Format strings.
library(magrittr)     # Pipelines for data processing: %>% %T>% %<>%.
library(rattle)       # Weather dataset.
library(readr)        # Read/write: read_csv().
library(scales)       # commas(), percent().

After loading the required packages into the library we access the rattle::weatherAUS dataset and save it into the template dataset named ds, as per the template based approach introduced by Graham J. Williams (2017). The dataset is modestly large and is used extensively in this book to illustrate the capabilities of R for the Data Scientist.

# Initialise the dataset as per the template.
dsname <- "weatherAUS"
ds     <- get(dsname)
names(ds) %<>% normVarNames()

ds %>% sample_frac()
## # A tibble: 226,868 × 24
##    date       location    min_temp max_temp rainfall evaporation sunshine
##    <date>     <chr>          <dbl>    <dbl>    <dbl>       <dbl>    <dbl>
##  1 2022-01-15 Hobart          16.2     25.7      0           3.8     NA  
##  2 2017-06-25 Ballarat         2.4     10.6      0.2        NA       NA  
##  3 2021-10-22 Katherine       NA       NA       NA          NA       NA  
##  4 2010-06-07 Newcastle       12       17.8     12.4        NA       NA  
##  5 2020-01-12 Walpole         13       25        0          NA       NA  
##  6 2020-11-06 SalmonGums       9       22.8      0          NA       NA  
##  7 2012-06-01 Tuggeranong      0.4     13.4      0          NA       NA  
##  8 2012-07-10 Brisbane        12.3     18.7      4.2         2.4      0  
##  9 2014-06-26 Albury           9.2     14.6      1.4        NA       NA  
## 10 2013-10-10 PearceRAAF       7.2     21.8      0.2        NA       11.5
## # ℹ 226,858 more rows
## # ℹ 17 more variables: wind_gust_dir <ord>, wind_gust_speed <dbl>,
....

References

Bache, Stefan Milton, and Hadley Wickham. 2022. Magrittr: A Forward-Pipe Operator for r. https://CRAN.R-project.org/package=magrittr.
Gagolewski, Marek, Bartek Tartanus, others; Unicode, Inc., et al. 2023. Stringi: Fast and Portable Character String Processing Facilities. https://CRAN.R-project.org/package=stringi.
Hester, Jim, and Jennifer Bryan. 2022. Glue: Interpreted String Literals. https://CRAN.R-project.org/package=glue.
———. 2022b. Stringr: Simple, Consistent Wrappers for Common String Operations. https://CRAN.R-project.org/package=stringr.
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Wickham, Hadley, Jim Hester, and Jennifer Bryan. 2023. Readr: Read Rectangular Text Data. https://CRAN.R-project.org/package=readr.
Wickham, Hadley, and Dana Seidel. 2022. Scales: Scale Functions for Visualization. https://CRAN.R-project.org/package=scales.
Williams, Graham. 2023. 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