19  Strings and Regex

Using g.r.e.p. (global regular expression print) and regular expressions (regex) to find character string patterns is a valuable tool in data analysis and is available with all operating systems and many different programming languages. It is a powerful tool once it is understood. The library(stringr) package makes these tools much easier to use.

The three tasks below can be completed in many different ways, but generally should not require many lines of code.

  1. Use the readr::read_lines() function to read in each: string—randomletters.txt and randomletters_wnumbers.txt.
  2. With the randomletters.txt file, pull out every 1700 letter (for example, 1, 1700, 3400, 5100, …) and find the quote that is hidden—the quote ends with a period.
  3. With the randomletters_wnumbers.txt file, find all the numbers hidden, and convert those numbers to letters using the letters order in the alphabet to decipher the message. For example, a 1=a, 2=b,…, 26=z (Hint: the message starts with “experts”).
  4. With the randomletters.txt file, remove all the spaces and periods from the string then find the longest sequence of vowels.
  5. Save your .R script (not .qmd) to your repository.

Submit

In I-learn submit a link to the script file on GitHub.