Skip to content
Related Articles

Related Articles

Reading and Writing Excel Files With R Using readxl and writexl

View Discussion
Improve Article
Save Article
  • Last Updated : 27 Jun, 2022

In this article let’s discuss reading and writing excel files using readxl and writexl packages of the R programming language.

read_excel() method in readxl Package:

The Readxl package is used to read data from the excel files i.e. the files of format .xls and .xlsx. The Readxl package provides a function called read_excel() which is used to read the data from excel files. The read_excel() method accepts the excel file which needs to read the content from it. In order to use the read_excel() method, first readxl library needs to be imported. 




  • excelFile – It specifies the excel file from which we read data.
  • sheet – It specifies from which work sheet we need to read. It is an optional parameter.

Note:- To install the Readxl package in R, use install.packages(“readxl”) command.

Syntax to install and import the readxl package:



Here let’s look into how to read the data from an excel file using read_excel() method present in Readxl package.

Link to the used file:- link


# import readxl package
# reading data from an excel file
data <-read_excel('stats.xlsx')  


 Name    Age Runs   Wickets
1 Akhil    21 143    14
2 Mriganka 32 1020   NA
3 Avinash  30 2022   2

write_xlsx() method in writexl package:

The writexl package provides a method called write_xlsx() method which allows writing a data frame into an excel sheet i.e. the files of format .xls and .xlsx. The write_xlsx() method accepts a data frame and the name of the excel file in which the content of the data frame is copied into it. In order to use the write_xlsx() method, the first writexl library needs to be imported.



write_xlsx(dataframeName, “excelFile”, col_names=TRUE)


  • dataframeName – Name of the data frame that contains the data.
  • excelFile – Name of the excel file into which we import from data frame.
  • col_names – Write column names at the top of file if it set to True.

Syntax to install and import the writexl package:



In the below code we created a data frame named “data” and imported the data in that data frame into the “write.xlsx” excel file using write_xlsx() method.

Link to the used file:- link


# import writexl library
# create a data frameĀ 
data <- data.frame(player=c('A', 'B', 'C', 'D'),
                runs=c(100, 200, 408, NA),
                wickets=c(17, 20, NA, 5))
# import data in dataframe to an excel sheet
write_xlsx(data, "write.xlsx")



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!