Site Last Updated: May 16, 2020

New R users should check out the R basics, visualization, and econometrics pages.

Python doesn’t have a monopoly on machine learning; check out my R for machine learning page.

I have a Google Scholar profile, from my previous life as an academic.


install_packages.R

I recommend writing and maintaining a script that keeps track of all the packages you regularly use. When re-imaging a workstation, or upgrading to the newest version of R, you can simply run it once (instead of installing packages one at a time). Here is an example:


RStudio Add-Ins

It’s worth your time to look for useful RStudio add-ins every so often. There are two add-ins in particular that make my life substantially easier:

  1. “AlignAssign” quickly aligns assignment operators, which when combined with RStudio’s “Reformat Code” function, makes writing pretty R code rather painless.
  2. “RStudio-Addin-Snippets” enables quick back-to-forward slash conversion (and vice-versa). This comes in handy when you are copying and pasting file paths from Windows (which use backslashes) into an R script (file paths in R must use forward slashes). Though you could escape every backslash in paths, it looks terrible and can make it more difficult to collaborate with colleagues programming on macOS or Linux (which both use forward slashes in paths).

For ease of use, I assign a keyboard shortcut to both of these add-ins in RStudio (Tools > Modify Keyboard Shortcuts).


Quietly Load Packages

You can avoid using the library() command with the power of lapply() when more than a handful of packages need to be loaded. Combine suppressMessages() with invisible() to completely suppress output.