How to read a dataset over http in R?

Asked

Viewed 104 times

2

I have access through a link:

'http://**.**.**.**/matrix/pesquisa_2019-03-17.feather'
ou
a<-readRDS('http://**.**.**.**/matrix/pesquisa_2019-03-17.rds')

But I can’t access them

a<-read_feather('http://**.**.**.**/matrix/pesquisa_2019-03-17.feather')
Error in normalizePath(path.expand(path), winslash, mustWork) : 
  path[1]="http://**.**.**.**/matrix/pesquisa_2019-03-17.feather": A sintaxe do nome do arquivo, do nome do diretório ou do rótulo do volume está incorreta

a<-readRDS('http://**.**.**.**/matrix/pesquisa_2019-03-17.rds')
Error in gzfile(file, "rb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "rb") :
  cannot open compressed file 'http://**.**.**.**/matrix/pesquisa_2019-03-17.rds', probable reason 'Invalid argument'

I was able to download it with download.file(), but I don’t want to take up hard drive space with him.
I also managed to do with read.csv2() with the help of: https://stats.idre.ucla.edu/r/modules/reading-in-data-from-an-external-file/

1 answer

2


I suggest adding the url() to readRDS(), type readRDS(url("...")). Example:

test <- readRDS( url("https://github.com/derek-corcoran-barrios/LastBat/raw/master/best2.My.Lu2.rds") )
str(test)

Note 1: The necessary Packages for the object . rds must be imported first.

Note 2: the url must be the correct one. In the case of the example I used, the file can be found in https://github.com/derek-corcoran-barrios/LastBat/blob/master/best2.My.Lu2.rds; but to work in readRDS, you have to use the url that originates the download in the browser. In this case is the https://github.com/derek-corcoran-barrios/LastBat/raw/master/best2.My.Lu2.rds

Browser other questions tagged

You are not signed in. Login or sign up in order to post.