Cyrus Mohammadian
Cyrus Mohammadian

Reputation: 5193

download xlsx from link and import into r

I know there are a number of posts on this topic and I usually am able to accomplish what I want just fine but I'm having trouble with this one particular link. It's likely related to the non-orthodox layout of the excel file. Here's my workflow:

library(rest)
url<-"http://irandataportal.syr.edu/wp-content/uploads/3.-economic-participation-and-unemployment-rates-for-populationa-aged-10-and-overa-by-ostan-province-1380-1384-2001-2005.xlsx"
unemp <- url %>%
  read.xls() 

That produces an error Error in getinfo.shape(fn) : Error opening SHP file

The problem is not related to the scraping of the data. The problem arises in regards to importing the data into a usable format. For example, read.xls("file.path/file.csv") produces the same error.

Upvotes: 0

Views: 2620

Answers (2)

Cyrus Mohammadian
Cyrus Mohammadian

Reputation: 5193

Adding the option fileEncoding="latin1" solved my problem.

url<-"http://irandataportal.syr.edu/wp-content/uploads/3.-economic-participation-and-unemployment-rates-for-populationa-aged-10-and-overa-by-ostan-province-1380-1384-2001-2005.xlsx"
unemp <- url %>%
   read.xls(fileEncoding="latin1") 

Upvotes: 0

tokiloutok
tokiloutok

Reputation: 467

For example :

library(RCurl)
download.file(url, destfile = "./file.xlsx")

use your favorite reader then,

Upvotes: 0

Related Questions