6.1 Strings Setup

20180720 Packages used in this chapter include dplyr (Wickham et al. 2021), glue (Hester 2020), magrittr (Bache and Wickham 2020), readr (Wickham and Hester 2020), stringr (Wickham 2019b), stringi (Gagolewski et al. 2021), scales (Wickham and Seidel 2020), 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(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: 176,747 x 24
##    date       location      min_temp max_temp rainfall evaporation sunshine
##    <date>     <chr>            <dbl>    <dbl>    <dbl>       <dbl>    <dbl>
##  1 2014-08-27 MountGinini       -1.3      4.9      0.6        NA       NA  
##  2 2019-03-20 Walpole           18       19.9      0.2        NA       NA  
##  3 2009-02-17 Newcastle         18.8     23.4      0          NA       NA  
##  4 2014-09-29 Tuggeranong        8.2     25.4      0          NA       NA  
##  5 2007-11-11 Canberra           9.1     25.2      0           4.2     11.9
##  6 2019-05-10 Woomera            4.6     16.2      3          NA       NA  
##  7 2011-01-18 Portland          12.5     17.3      0.2         3.2      0.9
##  8 2015-11-08 Watsonia           6.2     25.7      0           4.2     10.9
##  9 2012-06-03 Mildura            3.1     14.8      0           1.6      8.7
## 10 2015-06-26 BadgerysCreek      7.2     18.1      1          NA       NA  
## # … 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

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