Once you have a vector that consists of a bunch of file paths, you can do useful stuff with it, like renaming files in a consistent way. I can use sapply() to apply a function to every element of a vector. For example, I can use the file.rename() function along with the sub() function to change the filename.

If you aren’t familiar with sapply(), I highly recommend you take a moment to study up on how it works. Using the apply() family of functions is really important to being productive in R. Now my filenames look like this.

This is a whole lot faster and less error prone than trying to rename 500 files by hand. Just type ?files for a list of other file functions that might be useful, like file.move() and unlink(). Be careful with unlink()….it will delete files from your machine!