read_excel( )

Import Excel worksheets as a tibble. read_excel(), read_xls(), and read_xlsx() are from the readxl package.

Required Library

read_excel() is part of the tidyverse ecosystem, but it is not included in the core tidyverse package. Install and load the readxl package before using read_excel():

install.packages("readxl")
library(readxl)

Syntax

read_excel(path)

read_excel("file_name.xlsx") reads an Excel file (.xls or .xlsx) and returns a tibble data frame. By default, the first sheet of the Excel file is read, but you can specify a different sheet by name or position (see arguments below).

Examples

read_xls() and read_xlsx()
read_xls(path)

read_xls("file_name.xls") reads legacy Excel 97-2003 .xls files. Use this when the file extension is .xls or the workbook was saved in the older binary format.


read_xlsx(path)

read_xlsx("file_name.xlsx") reads modern Excel .xlsx files. Use this when the workbook is in Office Open XML format (.xlsx).

If you are not sure, use read_excel(). It auto-detects whether your file is .xls or .xlsx from the extension. Use read_xls() or read_xlsx() only when you want to force one file type.

Read the first worksheet from an Excel file
Read a specific worksheet

Select a worksheet by name.

Select a worksheet by position (e.g., second sheet).

Import only a selected cell range

You can also combine sheet and range:

Skip rows

This dataset has 3 title rows above the header:

Use skip = 3 to ignore them:

Handle custom missing value codes during import

The sheet Weights (missing) contains missing values that were entered in the spreadsheet as "N/A", "-", and "ND". They can be converted to NA during import by specifying them in the na argument:

Argument Overview

Required arguments must be included when using a function while optional arguments can be included on demand.

path — path to the Excel file character Required

A string giving the path to the Excel workbook. Use forward slashes (/) in file paths, even on Windows.

read_excel("data/results.xlsx")
read_excel("C:/Users/Morten/Documents/results.xlsx")

Data Types: character (file path)

sheet — worksheet to import character | integer Optional

Choose which worksheet to read by name or by position. Default is the first sheet.

read_excel("results.xlsx", sheet = "Dissolution")
read_excel("results.xlsx", sheet = 2)

Data Types: character | integer · Default: first sheet

range — cell range to read character Optional

Read a specific rectangular cell range using Excel notation. Useful when the worksheet contains extra notes or multiple tables.

read_excel("results.xlsx", range = "A1:D20")
read_excel("results.xlsx", range = "B3:F15")

Data Types: character (Excel-style range)

col_names — use first row as column names logical | character Optional

If TRUE (default), first row becomes column names. Set to FALSE to auto-generate names, or pass a character vector to define names manually.

read_excel("results.xlsx", col_names = FALSE)
read_excel("results.xlsx", col_names = c("tablet", "time_min", "absorbance"))

Data Types: logical | character vector · Default: TRUE

na — strings treated as missing values character vector Optional

Defines which strings should be converted to NA while importing. Useful when data entry used placeholders like "N/A" or "-".

read_excel("results.xlsx", na = c("", "N/A", "-", "Missing"))

Data Types: character vector · Default: ““

skip — number of rows to skip numeric Optional

Skips rows from the top before reading data. Useful for spreadsheets with titles or metadata above the header row.

read_excel("results.xlsx", skip = 2)

Data Types: numeric · Default: 0

n_max — maximum rows to read numeric Optional

Limits how many rows are imported. Useful for previewing large workbooks.

read_excel("results.xlsx", n_max = 100)

Data Types: numeric · Default: Inf