Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 从目录创建zip文件时出现问题_R_Zip - Fatal编程技术网

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

R 从目录创建zip文件时出现问题,r,zip,R,Zip,我在从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()的源代码,当我调

我在从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()函数是如何工作的,以及创建压缩文件夹需要做哪些更改

谢谢

编辑:在考虑注释的帮助后,我得到以下错误:

Browse[2]> system2(zip, args,stderr = T)
Error in system2(zip, args, stderr = T) : '"zip"' not found

已解决:在安装3.5版的Rtools后,它工作正常。

来自
zip
帮助:

zip(zipfile、文件、标志=“-r9X”、附加=“”, zip=Sys.getenv(“R_ZIPCMD”,“zip”))

压缩指定要使用的外部命令的字符串

如您所见,
zip
函数有一个参数
zip
,用于指定要使用的外部命令。在我的机器上:

λ where zip
C:\Oracle\Ora11\BIN\zip.exe
C:\Program Files\Rtools\bin\zip.exe
zip
程序在Rtools中可用,但通常在任何(Windows?)计算机上也可用

要检查R是否找到了
zip
,请键入:

> Sys.which("zip")
                              zip 
"C:\\Oracle\\Ora11\\bin\\zip.exe" 

如果您得到
,这意味着
zip
不在路径中,如果它既不在环境变量
R\u ZIPCMD
中,则必须在
zip
参数中指定其路径

是否要打印错误?可能使用
system2(“blablađ”,2,stderr=TRUE)
。您使用
zip()
的实际问题是什么?只是没有出现文件吗?是的,zip文件没有出现。我遇到了以下错误,我将编辑帖子。当您执行
Sys.which(“zip”)
?或者例如Do
zip(zipfile=“test.zip”,files=list.files(getwd()),zip=“C:\Program files\Rtools\bin\zip.exe”)
,假设这是一个zip程序的路径。
> Sys.which("zip")
                              zip 
"C:\\Oracle\\Ora11\\bin\\zip.exe"