我正在尝试将多个文件下载到一个文件夹中,然后将它们读回R
我首先将目录设置为特定文件夹 第一个http是主线,网址是应该下载的文件。
main_url <- "http://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP038/SRP038101/"
urls <- paste(main_url,c("SRR1171523/SRR1171523.sra","SRR1171524/SRR1171524.sra","SRR1171525/SRR1171525.sra","SRR1171526/SRR1171526.sra", "SRR1171527/SRR1171527.sra", "SRR1171528/SRR1171528.sra"), sep = "")
答案 0 :(得分:0)
你可以像下面那样继续......
main_url <-
"http://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP038/SRP038101/"
urls <-
paste(main_url,
c("SRR1171523/SRR1171523.sra",
"SRR1171524/SRR1171524.sra",
"SRR1171525/SRR1171525.sra",
"SRR1171526/SRR1171526.sra",
"SRR1171527/SRR1171527.sra",
"SRR1171528/SRR1171528.sra"),
sep = "")
for(i in seq_along(urls)){
download.file(urls[i], paste0("file_0", i, ".html"))
}
...而不仅仅是将下载的文件读入R。
答案 1 :(得分:0)
main_url <- "http://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP038/SRP038101/"
urls <- paste(main_url,c("SRR1171523/SRR1171523.sra","SRR1171524/SRR1171524.sra","SRR1171525/SRR1171525.sra","SRR1171526/SRR1171526.sra", "SRR1171527/SRR1171527.sra", "SRR1171528/SRR1171528.sra"), sep = "")
for(i in seq_along(urls)) {
tmp <- readLines(file(urls[i],open = "r"))
writeLines(text = tmp, con = paste0("url",1,".sra"))
}
# Reading them back
flist <- list()
for(fname in list.files()) {
flist[[fname]] <- readLines(file(fname, open="r"))
}
答案 2 :(得分:0)
下载它们的一种丑陋方式如下
url1 <- "http://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP038/SRP038101/SRR1171523/SRR1171523.sra"
url2 <- "http://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP038/SRP038101/SRR1171524/SRR1171524.sra"
url3 <- "http://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP038/SRP038101/SRR1171525/SRR1171525.sra"
url4 <- "http://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP038/SRP038101/SRR1171526/SRR1171526.sra
url5 <- "http://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP038/SRP038101/SRR1171527/SRR1171527.sra
url6 <- "http://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/SRP/SRP038/SRP038101/SRR1171528/SRR1171528.sra
download.file(url1, "SRR1171523.sra")
download.file(url2, "SRR1171524.sra")
download.file(url3, "SRR1171525.sra")
download.file(url4, "SRR1171526.sra")
download.file(url5, "SRR1171527.sra")
download.file(url6, "SRR1171528.sra")