Intermediate Importing Data in R
Import data into R from relational databases with SQL, from the web and JSON APIs, and from SAS, STATA and SPSS files, in interactive exercises.
This course is about getting data into R from relational databases, the web and other statistical software. You connect to a database and write SQL queries so the database does part of the computation and only the data you need comes back. You make HTTP requests to download files and call APIs that return JSON. You also read SAS, STATA and SPSS files with the haven and foreign packages.
What You Will Achieve
- Connect R to a relational database, list its tables and import the ones you need
- Send SQL queries from R, fetch the results and clear them when the work is done
- Download files over HTTP and turn JSON from an API into R objects with httr and jsonlite
- Load SAS, STATA and SPSS data with haven or foreign and check what was imported
Program Overview
Relational Databases and SQL Queries in R
Linking R to a database, bringing in its tables, and moving computation to the database side with SQL.
- Establishing and inspecting a connection
- How database tables relate
- SQL queries and joins run from inside R
- DBI internals and result handling
Web Data over HTTP, APIs and JSON
Importing files stored on the web and extracting structured information from APIs.
- HTTP basics and secure imports
- Flat, Excel and text files read from the web
- Requests with httr
- JSON with jsonlite, toJSON, minify and prettify
Files from SAS, STATA and SPSS
Reading the file formats of other statistical software packages into R with two different packages.
- Importing with haven
- Importing with foreign
- Turning imported values into factors
- A short excursion into correlation
Certificate Awarded (Paid)
Job Outlook
These skills are used wherever analysts work in R with information held in company databases, web APIs or files produced by SAS, STATA and SPSS.
Good for: R users who need to pull data from databases, web APIs and other statistical packages into their own analyses.
Keep in mind: Each chapter is built around specific R packages, including DBI, httr, jsonlite, haven and foreign, so the skills tie closely to those tools.
Bottom line: A practical run through three import routes into R: databases with DBI and SQL, web data with httr and jsonlite, and other packages’ files with haven and foreign.
Frequently Asked Questions
Which R packages does the course use?
The database chapters work through DBI, the web chapters use httr for HTTP requests and jsonlite for JSON, and the final chapter reads statistical software files with both haven and foreign, so you see two ways of doing the same job.
Which web API appears in the exercises?
The JSON chapter has you call the OMDb API and convert its JSON response into R objects. You then practice turning R data back into JSON and switching between minified and prettified output.
Why send SQL queries instead of importing whole tables?
Importing an entire table when you need only a small part of it is wasted effort. Queries let the database handle some of the computation, including joins, so R receives just the data you asked for.


There are no reviews yet.