celestialgod

download data from database

Jun 21st, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.78 KB | None | 0 0
  1. library(httr)
  2. library(pipeR)
  3. library(xml2)
  4. library(rvest)
  5. library(stringr)
  6.  
  7. testurl = "https://tcga-data.nci.nih.gov/tcga/findArchives.htm"
  8.  
  9. x = POST(testurl, body = list(project = -1, center = -1, platform = -1, dataType = 29, archiveType = 2,
  10.   fileName = "", dateStart="01/01/2016", dateEnd = "06/18/2016", ec_crd = 15, ec_p = 2), encode = "form") %>>%
  11.   content %>>%
  12.   xml_find_one("//table[@id='ec_table']") %>>% xml_find_all("//td[a='Download']/a") %>>%
  13.   (.[xml_text(.) == "Download"]) %>>% lapply(xml_attr, attr = "href") %>>%
  14.   str_extract("/tcgafiles/ftp_auth/distro_ftpusers/anonymous/[^']+") %>>%
  15.   (str_c("https://tcga-data.nci.nih.gov", .))
  16.  
  17. sapply(x, function(y){
  18.   download.file(y, destfile = str_extract(y, "mdanderson.org_.*gz"))
  19. })
Add Comment
Please, Sign In to add comment