gpt4 book ai didi

r - 从目录创建 zip 文件时出现问题

转载 作者:行者123 更新时间:2023-12-04 01:53:14 26 4
gpt4 key购买 nike

我在从 R 创建 zip 文件时遇到问题。相同的代码在 R 版本 3.4.2、32 位计算机上工作得很好。

现在我试图在 R 版本 3.5.1、64 位计算机上运行相同的东西,而 zip() 命令似乎不起作用。到底是怎么回事?

zip(zipfile = "test.zip",files=list.files(getwd())) 
#create zip from whole directory, on 1st machine it works, now nothing happens

我检查了 zip() 的源代码,当我调试它时,我发现 system2 命令什么也不做。
  zip <- function (zipfile, files, flags = "-r9X", extras = "", zip = Sys.getenv("R_ZIPCMD", 
"zip"))
{
if (missing(flags) && (!is.character(files) || !length(files)))
stop("'files' must a character vector specifying one or more filepaths")
args <- c(flags, shQuote(path.expand(zipfile)), shQuote(files),
extras)
if (.Platform$OS.type == "windows")
invisible(system2(zip, args))
else invisible(system2(zip, args))
}

# I run this manually when trying to debug, nothing happens;
system2(zip, args) ## zip is a parameter here, not a function
####
Browse[2]> zip
[1] "zip"
Browse[2]> args
[1] "-r9X" "\"bla.zip\""
[3] "\"[Content_Types].xml\"" "\"_rels\""
[5] "\"docProps\"" "\"xl\""
[7] ""

例如,荒谬的调用不会给出错误。
system2("blablađ",2) ## does nothing but no error or warning either

我一直试图了解 system2() 函数的工作原理以及我需要更改什么才能创建压缩文件夹。

谢谢

编辑:从评论中获取帮助后,我收到以下错误:
Browse[2]> system2(zip, args,stderr = T)
Error in system2(zip, args, stderr = T) : '"zip"' not found

已解决:安装 3.5 版的 Rtools 后,它可以工作了。

最佳答案

来自 zip帮助:

zip(zipfile, files, flags = "-r9X", extras = "", zip = Sys.getenv("R_ZIPCMD", "zip"))

zip A character string specifying the external command to be used.



如您所见, zip函数有一个参数 zip指定要使用的外部命令。在我的机器上是:
λ where zip
C:\Oracle\Ora11\BIN\zip.exe
C:\Program Files\Rtools\bin\zip.exe
zip程序在 Rtools 中可用,但通常也可以在任何(Windows?)机器上使用。

检查是否 zip由 R 找到,输入:
> Sys.which("zip")
zip
"C:\\Oracle\\Ora11\\bin\\zip.exe"

如果您收到 "" ,这意味着 zip不在路径中,如果不在环境变量中 R_ZIPCMD ,您必须在 zip 中指定其路径争论。

关于r - 从目录创建 zip 文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52008932/

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