Manual string manipulation for a figure is painful! With a little knowledge, we can manipulate strings in R using the stringr and glue packages. We'll focus on using regular expressions with str_replace and see how we can save and reuse the matched parttern in the outputted string. In this Code Club we'll see how we can use functions from these packages to manipulate strings to combine bacterial taxa names with an OTU designation.
Pat will use RStudio and functions from the #stringr, #glue, and #ggplot2, package. The accompanying blog post can be found at https://www.riffomonas.org/code_club/2021-06-01-working-with-text.
Do you have a figure that you would like to receive a critique or help improving? Let me know and I'd be happy to arrange a guest appearance!
If you're interested in taking an upcoming 3 day R workshop, check out website at https://www.mothur.org/wiki/workshops
R: https://r-project.org
RStudio: https://rstudio.com
Raw data: https://github.com/riffomonas/raw_data/releases/latest
Workshops: https://www.mothur.org/wiki/workshops
You can also find complete tutorials for learning R with the tidyverse using...
Microbial ecology data: https://www.riffomonas.org/minimalR/
General data: https://www.riffomonas.org/generalR/
0:00 Introduction
2:39 Quantifiers and regular expression
9:18 Applying quantifiers
13:58 Joining text with glue
16:46 Saving portions of a matched pattern
20:26 Refactoring code
22:48 Reordering OTUs
24:16 Inserting line breaks into regular expressions
26:21 Recap