5.5 Downloading files

When all else fails, or files are in a format that can’t be parsed directly by an existing R package, downloading files is simple using base R.

The GSS datasets we’re using are retrieved when building this book using the base R download and unzip methods.

# Download datasets
download.file("http://gss.norc.org/Documents/spss/2018_spss.zip", "data/gss_2018_spss.zip")
download.file("http://gss.norc.org/Documents/stata/2018_stata.zip", "data/gss_2018_stata.zip")

# Unzip
unzip("data/gss_2018_spss.zip", exdir = "data/gss")
unzip("data/gss_2018_stata.zip", exdir = "data/gss")

If you need to authenticate yourself, or to construct a more complex web request, httr is always a safe bet.