Introduction to Importing Data in R
Learn to import CSV, tab-delimited text and Excel files into R with base functions, readr, data.table, readxl and XLConnect.
Getting a dataset into R is often harder than it should be, since data arrives in many formats and each one calls for its own approach. You learn to read comma-separated and tab-delimited text files, set column names and column types as the data loads, and pull individual sheets out of Excel workbooks. The final part goes further with Excel, editing workbooks inside R so the spreadsheet can stay part of a repeatable workflow.
What You Will Achieve
- Load CSV and tab-delimited text files with base R and assign the right column names and classes
- Choose between readr and data.table for a large flat file and limit which rows and column types get read
- List the sheets in an Excel file and import only the ones an analysis needs
- Add, populate, rename and remove worksheets in an Excel workbook directly from R
Program Overview
Flat Files with Base R Functions
The utils functions that ship with R for reading simple tabular text files, including how to point R at a file path.
- read.csv and reading from a path
- read.delim and read.table
- Assigning column names and column classes
Efficient Flat File Imports with readr and data.table
Two dedicated packages that read flat files more consistently, with finer control over the rows and column types that get loaded.
- read_csv, read_tsv and read_delim
- skip, n_max and col_types with collectors
- fread and its more advanced use
- Dedicated classes for imported data
Excel Data with readxl and Reproducible Work with XLConnect
Reading sheets with readxl, then connecting to workbooks through XLConnect to read, adapt and manage sheets inside R.
- Listing and importing sheets with readxl
- The col_names and skip arguments
- Connecting to a workbook and customizing readWorksheet
- Adding, populating, renaming and removing sheets
Certificate Awarded (Paid)
Job Outlook
Loading external data cleanly is the first step of most analysis work in R, so these skills apply wherever analysts and data scientists receive CSV exports, delimited text files or Excel workbooks before starting an analysis.
Good for: R users who regularly receive CSV exports, delimited text files or Excel workbooks and want a dependable way to load each one before analysis.
Keep in mind: The four chapters center on flat text files and Excel workbooks; statistical software files, databases and HTML data are not imported in any lesson.
Bottom line: A practical side-by-side look at base R, readr, data.table, readxl and XLConnect on flat files and Excel workbooks.
Frequently Asked Questions
Why are several packages taught for the same file types?
Each one suits a different situation. Base R functions need no extra packages, readr and data.table read flat files faster and more consistently, and readxl and XLConnect give increasing control over Excel workbooks, so you can pick the tool that fits each file.
How does XLConnect differ from readxl?
readxl is used here to list and read sheets from an Excel file. XLConnect connects to a whole workbook, reads and customizes worksheets, and also adds, populates, renames and removes sheets, which keeps Excel inside a reproducible R workflow.
Which import settings can I control while reading a file?
In base R you assign column names and column classes. With readr you set skip, n_max and col_types, including collectors, while readxl offers the col_names and skip arguments for Excel sheets. The fread function from data.table also gets a look at its more advanced options.
What counts as a flat file in R?
A flat file is a simple tabular text file, such as a comma-separated or tab-delimited one. The first half of the course reads these with the utils functions in base R and then with the readr and data.table packages.


There are no reviews yet.