我有一个370MB的zip文件,内容是4.2GB的csv文件.
我做了:
unzip("year2015.zip", exdir = "csv_folder")
Run Code Online (Sandbox Code Playgroud)
我收到了这条消息:
1: In unzip("year2015.zip", exdir = "csv_folder") :
possible truncation of >= 4GB file
Run Code Online (Sandbox Code Playgroud)
你以前经历过吗?你是怎么解决的?
我同意@Sixiang.Hu的回答,R的unzip()无法可靠地处理大于4GB的文件.
要了解你是如何解决它的?:我已经尝试了一些不同的技巧,根据我的经验,任何使用R的内置函数的结果(几乎)总是在实际结束之前不正确地识别文件结束(EOF)标记.文件.
我在每晚处理的一组文件中处理这个问题,并且为了一致并以自动方式处理它,我编写了下面的函数来包装UNIX解压缩.这基本上就是你用system(unzip())做的事情,但是它给你的行为提供了更多的灵活性,并允许你更系统地检查错误.
decompress_file <- function(directory, file, .file_cache = FALSE) {
if (.file_cache == TRUE) {
print("decompression skipped")
} else {
# Set working directory for decompression
# simplifies unzip directory location behavior
wd <- getwd()
setwd(directory)
# Run decompression
decompression <-
system2("unzip",
args = c("-o", # include override flag
file),
stdout = TRUE)
# uncomment to delete archive once decompressed
# file.remove(file)
# Reset working directory
setwd(wd); rm(wd)
# Test for success criteria
# change the search depending on
# your implementation
if (grepl("Warning message", tail(decompression, 1))) {
print(decompression)
}
}
}
Run Code Online (Sandbox Code Playgroud)
笔记:
该功能做了一些事情,我喜欢并推荐:
system2系统,因为文档说"system2是一个比系统更便携和灵活的接口" directory和file参数,并将工作目录移动到directory参数; 取决于你的系统,解压缩(或你选择的解压缩工具)在解压缩工作目录之外的档案时变得非常挑剔
.file_cache允许您跳过解压缩的参数
if+ grepl检查在stdout中查找警告,如果找到该表达式则打印stdout检查?unzip,发现以下评论Note:
它确实支持bzip2压缩和> 2GB zip文件(但不包含zip文件中包含的> = 4GB文件预压缩:就像许多解压缩版本一样,它可能会截断这些,如果可能的话,在R的情况下会发出警告).
你可以尝试在R之外解压缩它(例如使用7-Zip).
| 归档时间: |
|
| 查看次数: |
872 次 |
| 最近记录: |