我有一个多步骤的文件下载过程中,我想在R做我有中间的一步,但不是第一个和第三个......递归ftp下载,然后解压GZ文件
# STEP 1 Recursively find all the files at an ftp site
# ftp://prism.oregonstate.edu//pub/prism/pacisl/grids
all_paths <- #### a recursive listing of the ftp path contents??? ####
# STEP 2 Choose all the ones whose filename starts with "hi"
all_files <- sapply(sapply(strsplit(all_paths, "/"), rev), "[", 1)
hawaii_log <- substr(all_files, 1, 2) == "hi"
hi_paths <- all_paths[hawaii_log]
hi_files <- all_files[hawaii_log]
# STEP 3 Download & extract from gz format into a single directory
mapply(download.file, url = hi_paths, destfile = hi_files)
## and now how to extract from gz format?
行必须将其为R? HTTP最适合使用,但在FTP上并不完美。更通用的语言,比如Python,会更适合这类问题。 – chmullig 2011-03-08 02:35:41
是的,我试图避免添加任何外部工具......现在我已经通过调用R的命令行wget做了一个解决方法,但是我希望能够将它作为一个独立的R传递给某个人脚本 – 2011-03-08 02:52:29
只需复制和粘贴文本文件名并在一个循环中使用download.file就足够简单了 - 因此它为您的用户进行了硬编码,但仍然是独立的(或者您可以通过ftp进入站点和mget ...) – mdsumner 2011-03-08 03:02:09