【发布时间】:2018-05-02 09:55:06
【问题描述】:
我正在尝试在 R 中压缩多个 CSV 文件。下面是供参考的代码。
# Create two dataframes using inbuilt datasets for reproducible code
df1 <- head(mtcars)
df2 <- head(iris)
# Write the files as CSV into working directory
write.csv(df1, file = "Test_File1.csv", row.names = FALSE, quote = FALSE)
write.csv(df2, file = "Test_File2.csv", row.names = FALSE, quote = FALSE)
# Read the 2 CSV file names from working directory
Zip_Files <- list.files(path = getwd(), pattern = ".csv$")
# Zip the files and place the zipped file in working directory
zip(zipfile = "TestZip", files = Zip_Files)
我收到以下警告消息。 Zip 文件尚未创建。
Warning message:
running command '"zip" -r9X "TestZip" "Test_File1.csv" "Test_File2.csv" ' had status 127
我什至尝试了这个命令来读取 CSV 文件名:Zip_Files <- list.files(path = getwd(), pattern = ".csv$", full.names = TRUE) 但我仍然收到上面显示的警告消息。我的电脑中已经安装了WinRAR 和7-Zip。我正在使用最新版本的 R(3.4.2 64 位)以及最新版本的 RStudio。我有一个 Windows 7 x64 操作系统。对此的任何帮助将不胜感激。
【问题讨论】:
-
如果您查看帮助文件
?zip,它会显示“在 Windows 上,默认依赖于路径中的 zip 程序(例如来自 Rtools 的程序)。”您的路径中似乎没有名为“zip”的程序。尝试打开命令提示符并键入“zip -h”。您是否收到“不被识别为内部或外部命令”? -
没错@G5W。我刚刚打开命令提示符并按照建议输入
zip-h。我收到'zip' is not recognized as an internal or external command, operable program or batch file. -
你的机器上有压缩和解压文件的程序吗?
-
是的,我愿意。正如我的帖子中已经提到的,我的电脑中同时安装了
WinRAR和7-Zip。
标签: r csv dataframe zip zipfile