gpt4 book ai didi

r - 无法在不包含完整文件路径的情况下从 R 中压缩目录

转载 作者:行者123 更新时间:2023-12-01 04:40:49 27 4
gpt4 key购买 nike

我有一个 R 脚本(pdf、csv 文件)的输出目录,我想在每次运行代码时对其进行压缩(从 utils 包中压缩)。

>path_out
I:\\full\\path\\to\\file\\
>files2zip <- dir(path_out, full.names = TRUE)
>zip(zipfile = paste(path_out,unitList[ii],"_",Sys.Date(),sep=""), files = files2zip)

这会痛苦地生成一个 zip 文件,文件中包含完整路径目录:
>unzip(zipfile = paste(path_out,unitList[ii],"_",Sys.Date(),".zip",sep=""), list = TRUE, junkpaths = FALSE)
Date
/full/path/to/file/file1.pdf 7978 2018-04-16 13:44:00
/full/path/to/file/file2.pdf 6665 2018-04-16 09:14:00
/full/path/to/file/file3.pdf 6557 2018-04-15 11:22:00
/full/path/to/file/file4.csv 627 2018-03-27 11:10:00

在 Bash zip 中有一个 -j 标签,它会破坏完整路径并且只包含相对路径。有没有办法在R中做到这一点?

最佳答案

您可以使用 extras zip() 的参数功能。

所以:

zip(zipfile = paste(path_out,unitList[ii],"_",Sys.Date(),sep=""), files  = files2zip, extras = '-j')

关于r - 无法在不包含完整文件路径的情况下从 R 中压缩目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50339737/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com