我有一個多步驟的文件下載過程中,我想在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