Cheat Sheet Updated: 09/16. Matches at least 0 times + Matches at least 1 time? Matches at most 1 time; optional string. Stringr::strextractall(string, pattern, simplify = TRUE) extract all matches, outputs a matrix stringr::strmatch(string, pattern). The stringr package provides an easy to use toolkit for working with strings, i.e. Character data, in R. This cheatsheet guides you through stringr’s functions for manipulating strings. The back page provides a concise reference to regular expresssions, a mini-language for describing, finding, and matching patterns in strings.
Introduction to stringr. There are four main families of functions in stringr: Character manipulation: these functions allow you to manipulate individual characters within the strings in character vectors. Whitespace tools to add, remove, and manipulate whitespace. Locale sensitive operations whose operations will vary from locale to locale. The smooth ## 2 Glue the sheet to the dark blue background. The sheet ## 3 It's easy to tell the depth of a well. The depth ## 4 These days a chicken leg is a rare dish. A chicken ## 5 Rice is often served in round bowls.
So, kinda the whole point of this “making-a-blog” endeavor (aside from getting to play with Yihui Xie’s super awesome blogdown
📦) was to give a more permanent home to some of the resources I’ve found and/or tweeted. So, without further ado…
stringr
«aide-mémoire»
This visual guide (or cheat sheet, if you prefer) was made by Lise Vaudor (@LVaudor on twitter), and originally shared in her blog post, Manipuler des strings avec R.
AutomountMaker is a tool for mounting filesystems of type AFP, FTP, http, NFS, SMB. After having created your files of script you can open 'System Preference', choose 'Login' and drag and drop in the list. The download version of AutomountMaker for Mac is 1.4.7. The package you are about to download is authentic and was not repacked or modified in any way by us. AutomountMaker antivirus report. This download is virus-free. This file was last analysed by Free Download Manager Lib 8 days ago. Automountmaker. AutomountMaker is designed to help you eliminate repetitive actions when mounting network volumes: the app creates scripts that you can run with a mouse click or include in the list of login items.
In case you hadn’t caught on, her blog is in French 🇫🇷, and, while Google translate does a pretty solid job of rendering it en anglais, someone else (@suman12029) found it to be so darn helpful that they translated it into English 🇬🇧 and posted it here on GitHub.
Regardless of language, it’s a helpful intro to the stringr
📦. So, go check it out!
The cheat sheet itself needs no translation 🌏:
Just for kicks, I also exported a version as a pdf, but 💯% of the credit belongs to Lise Vaudor.
Fin
Square parentheses []
and the asterisk *
Tidyverse Stringr Cheat Sheet
We can match a group of characters or digits using the square parentheses. Here I’m going to use a new function, str_extract(). This does as it says on the tin, it extracts the parts of the text that match our pattern. For instance the last lower case letter in each element of the vector, if such a thing exists
Notice that one of the files ends with an upper case letter, so we get an NA. To include this we add “A-Z”' (to add numbers we add 0-9 and to add metacharacters we write them without escaping them)
Now, this is obviously useless at the moment. This is where does the asterisk comes into it. The asterisk is what is called a quantifier. There are three other quantifiers (+
, ?
and {}
), but won’t cover them here. A quantifier quantifies how many of the characters we want to match and the asterisk means we want 0 or more characters of the same form. For instance, we could now extract all of the file extensions if we wished to
So we go backwards from the end of the line collecting all the characters until we hit a character that isn’t a lower or upper case letter. We can now use this to grab the group letters preceeding the file extensions for our task
Obviously we still have some pesky files in there that we don’t want. We now actually have all the tools to complete the task. The filenames we want take the form project-objects or project_objects, so we know that preceeding that block of letters for “objects” we want either a dash or an underscore. We can use a group and pipe for this
We still have two pesky files sneaking in there. How do those two files and the three files we want differ? Well the files we want all start with project-
or project_
where as the other two don’t. We must also take note that the project could have a capital “P”. We can combat that using a group!
If we had a huge file list, we’d want to stop files such as 2Project_Trees.csv
filtering in as well. So we can just use the hat to specify the start of a line
Stringr R Cheat Sheet
If you do any higher level programming, regular expressions are definitely a trade worth learning. They play a big role in modern data analytics. For a good table of metacharacters, quantifiers and useful regular expressions, see this Microsoft page or the RStudio stringrcheat sheet.
Rstudio Cheat Sheets
Source: inspired by the source material here