Dom
Dom

Reputation: 1053

Opening/reading an excel file in r

I am having trouble opening/reading excel files that I download from the website of the Australian Bureau of Statistics using readxl.

I've downloaded Table 12 from the website but when I go to read the sheets of the workbook in r I get an error message:

library(readxl)    
excel_sheets(path = "C:/Users/Name/Documents/downloaded_file.xls")

"Error in xls_sheets(path) : Failed to open C:/Users/Name/Documents/downloaded_file.xls".

In previous versions of readxl I have had no trouble reading these files into r but I've recently updated my readxl version, after a hiatus of several months, and now it doesn't work.

I have tried to download the file using the download.file function taking care to set mode = wb but that makes no difference to being able to access the data in the workbook either.

Grateful for any pointers.

Upvotes: 0

Views: 716

Answers (2)

Iman
Iman

Reputation: 2324

It Works on Windows:

library(readxl)    
excel_sheets(path = "C:/Users/Name/Documents/downloaded_file.xls")
data<-readxl::read_excel(path = ""C:/Users/Name/Documents/downloaded_file.xls"",sheet = "Data1")

Upvotes: 0

Manuel Bickel
Manuel Bickel

Reputation: 2206

Have you tried other packages. If I download the file manually and read it with xlsx it works for me. Is below ouptut what you need or am I missing something?

library("xlsx")
# there is certainly a better (faster) way to get the sheet number
n_sheets =  length(getSheets(loadWorkbook("6202012.xls")))
# if you know which sheet to load, reading the sheet works for me...
df = read.xlsx("6202012.xls", 2)
df[1:3, 1:3]
#            NA. Employed.total....Persons....Australia.. Employed.total....Persons....Australia...1
# 1        Unit                                      000                                        000
# 2 Series Type                                    Trend                        Seasonally Adjusted
# 3   Data Type                                    STOCK                                      STOCK

Upvotes: 0

Related Questions