6 Beyond Basics


6.1 The R Ecosystem

Use expansion “packages” for common procedures and more functionality

6.1.1 Packages

CRAN Most packages can be found on CRAN and can be easily installed

## commonly used packages
install.packages("stargazer")
install.packages("data.table")
## install.packages("purrr")
## install.packages("reshape2")

The most common tasks also have cheatsheets you can use. E.g., https://github.com/rstudio/cheatsheets/blob/main/rstudio-ide.pdf

Github Sometimes you will want to install a package from GitHub. For this, you can use devtools or its light-weight version remotes

install.packages("devtools")
install.packages("remotes")

Note that to install devtools, you also need to have developer tools installed on your computer.

To color terminal output on Linux systems, you can use the colorout package

library(remotes)
# Install https://github.com/jalvesaq/colorout
# to .libPaths()[1]
install_github('jalvesaq/colorout')
library(colorout)

Base While additional packages can make your code faster, they also create dependancies that can lead to problems. So learn base R well before becoming dependant on other packages

6.1.2 Task Views

Task views list relevant packages.

For all students and early researchers,

For microeconometrics,

For spatial econometrics

Multiple packages may have the same function name for different commands. In this case use the syntax package::function to specify the package. For example

devtools::install_github
remotes::install_github

Don’t fret Sometimes there is not a specific package for your data.

Odds are, you can do most of what you want with base code.

Statisticians might have different naming conventions

  • if the usual software just spits out a nice plot you might have to dig a little to know precisely what you want
  • your data are fundamentally numbers, strings, etc… You only have to figure out how to read it in.

6.2 Introductions to R

There are many good yet free programming books online. Some of my examples originally come from https://r4ds.had.co.nz/ and I recommend https://intro2r.com. But I have used online material from many places over the years, including

What we cover in this primer should be enough to get you going. But there are also many good yet free-online tutorials and courses.

6.3 Custom Figures

Many of the best plots are custom made (see https://www.r-graph-gallery.com/). Here are some ones that I have made over the years.

knitr::opts_chunk$set(echo=TRUE, message=FALSE, warning=FALSE)