简体   繁体   中英

Use magrittr to pipe download.file() to another function

How can I use magrittr to pipe the output of download.file() directly to readxl() without first saving to a temporary location?

For example, I have the following code:

download.file(www, method="curl") %>%
  read_excel(x, sheet ="List 1", range="A3:L1902") -> cw

This gives me an error because I am missing the destfile= argument... any ideas?

I tried the idea of connections but from my searches readxl doesn't support reading from urls (you can look here and here ). However, I found here something that might help you.

The rio package have a wrapper around read_excel which allow the use of urls. You can even add the argument sheet to chose which sheet to load. In addition, from my experience, if you know the file extension you'll use - add the format argument.

install.packages("rio") # if needed

df <- rio::import("https://evs.nci.nih.gov/ftp1/CDISC/SDTM/SDTM%20Terminology.xls", 
                      format = "xls", sheet = "SDTM Terminology 2018-03-30")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM