A New Week!



We aren’t computer scientists and that’s okay!

We make lots of mistakes. Mistakes are funny. You can laugh with us.

Let’s go, Simba, Pumbaa, and Timon!





1 string basics


We will focus on the stringr package for string manipulation.

All functions from stringr start with str_.

stringr cheatsheet

https://evoldyn.gitlab.io/evomics-2018/ref-sheets/R_strings.pdf


1.1 string length

Use str_length() to find the number of characters in a string.

1.3 subsetting strings

Use str_sub() to extract parts of a string based on index.

1.4 convert case

str_to_lower() & str_to_upper()

1.5 sort strings

str_sort()

2 regular expressions


Regular expressions, or regexps, are a concise language for describing patterns in strings.

In R, we write regular expressions as strings.

We will use str_view() to learn regular expression

For more patterns with regular expressions, please check the stringr cheatshet.


3 match strings


3.2 str_detect()

To determine if a character vector matches a pattern. It returns a logical vector.

You can also combine str_detect() and filter() to select rows in a dataframe.

4 Recap



  • string basics

  • regular expressions

  • match strings