从网页读取所有.tar.gz文件
我需要从
fn <- "https://www.ncei.noaa.gov/data/global-hourly/archive/csv/1901.tar.gz"
download.file(fn,destfile="tmp.tar.gz")
file_names <- untar("tmp.tar.gz",list=TRUE)
ISDGlobalHourlyData <- do.call(dplyr::bind_rows,lapply(file_names,read.csv))
但是对于每个文件来说,单独执行此操作太耗时了。有没有一种方法可以用一个函数阅读它们?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很大(&gt; 4gb),因此您可能需要在连接时间之前增加秒数,并且删除tmp.tar.gz可能是一个好主意以及将其加载到R中后的CSV文件,但这取决于您。
另外,在运行此操作之前,
dir_ls()
命令在您的工作目录中搜索名为'digits'.csv(例如“ 0296009999999.CSV”)中的所有.csv文件);如果您具有具有相同命名方案的其他.CSV文件,则可能必须相应地更改正则命名(例如Digits'.csv的X X)。这是一种可能合适的方法:
由
Some of the files in https://www.ncei.noaa.gov/data/global-hourly/archive/csv/ are quite large (>4Gb) so you may need to increase the seconds before the connection times out and it's probably a good idea to delete tmp.tar.gz and the csv files after they've been loaded into R, but it's up to you.
Also, before you run this, the
dir_ls()
command searches for all .csv files in your working directory named 'digits'.csv (e.g. "02960099999.csv"); if you have other .csv files with the same naming scheme, you may have to alter the regex accordingly (e.g. 'x number of digits'.csv).Here is one approach that might be suitable:
Created on 2022-06-21 by the reprex package (v2.0.1)