Reading excel files with readxl R package

< 1 min. read

Recently, Hadley Wickham introduced a new package to read Excel files (XLS, XLSX). The main advantage is that no external dependencies is required for readxl. (xlsx package requires Java Runtime to be installed)

With xlsx:

library(xlsx)
library(httr)
url <- "https://rawgit.com/yoke2/dsxref/master/iris.xlsx"
GET(url, write_disk("iris.xlsx", overwrite=TRUE))
iris <- read.xlsx("iris.xlsx", sheetIndex=1, header=TRUE)
head(iris, 3)
##   NA. Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1   1          5.1         3.5          1.4         0.2  setosa
## 2   2          4.9         3.0          1.4         0.2  setosa
## 3   3          4.7         3.2          1.3         0.2  setosa

With readxl:

library(readxl)
library(httr)
url <- "https://rawgit.com/yoke2/dsxref/master/iris.xlsx"
GET(url, write_disk("iris.xlsx", overwrite=TRUE))
iris <- read_excel("iris.xlsx")
head(iris, 3)
##     Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 1          5.1         3.5          1.4         0.2  setosa
## 2 2          4.9         3.0          1.4         0.2  setosa
## 3 3          4.7         3.2          1.3         0.2  setosa

Find out more on the features, usage and installation at its Github repository.