3

The GetURL function from the "RCurl" package is a fantastic tool for reading in content from ftp, https, ect. I have used the package a lot of times to read in .csv and .txt, but when it comes to .xlsx it has some problems. I found out on this forum, that xlsx is a binary format and thus it cannot be teated as a normal text-string like .csv and .txt.

The FTP-servers often has security as a password and a user name, and therefore functions such as "download.file" will result in some issues when reading in ".xlsx"-file. I then tried the getBinaryURL but the output format is "raw" and i can not get a data.frame from this format - neither from the functions rawToChar() or rawRoBin().

if(!require(RCurl)) install.packages("RCurl");library(RCurl)

url <- "ftp://..."
userpwd <- "user:pwd"

out <- getBinaryURL(url, userpwd = userpwd,
                    ftp.use.epsv = FALSE,crlf = TRUE)

Any suggestions on how I can read in a .xlsx from a ftp-server into R as a data frame?

1 Answers1

2

Create a temp file with a connection, write your data to it and then read this file with read_xlsx.

Mytmpfile = tempfile()
getBinaryURL(url, userpwd = userpwd, ftp.use.epsv = FALSE,crlf =TRUE)%>%writeBin(con=Mytmpfile)
Df = read_xlsx(Mytmpfile, sheet='x')
barbsan
  • 3,418
  • 11
  • 21
  • 28