解压受密码保护的归档文件,并将包含的SPSS文件读入R

解压受密码保护的归档文件,并将包含的SPSS文件读入R,r,spss,hmisc,R,Spss,Hmisc,我有一个密码保护的zip存档,其中包含一个SPSS系统数据文件(*.sav)。我想把它解包并把它的内容读入R。从我的谷歌搜索结果来看,Hmisc::getZip似乎是最好的选择。我尝试了一些不同的方法 第一次尝试只是运行函数,希望它能在我的getwd()位置中吐出*.sav文件 getZip(url = '/path/to/data.zip', password = 'foo' ) 但此命令返回: "unzip -p -P foo data.zip" class "pipe" mo

我有一个密码保护的zip存档,其中包含一个SPSS系统数据文件(*.sav)。我想把它解包并把它的内容读入R。从我的谷歌搜索结果来看,
Hmisc::getZip
似乎是最好的选择。我尝试了一些不同的方法

第一次尝试只是运行函数,希望它能在我的
getwd()
位置中吐出
*.sav
文件

getZip(url = '/path/to/data.zip', 
  password = 'foo'
)
但此命令返回:

"unzip -p -P foo data.zip" 
class 
"pipe" 
mode 
"r" 
text 
"text" 
opened 
"closed" 
can read 
"yes" 
can write 
"yes" 
读取帮助文件后,
getZip()
函数似乎会返回一个文件O/I管道。所以我的第二次尝试是在
read.spss()中使用
getZip()
。像这样:

data <- read.spss(getZip(url = '/path/to/data.zip', 
  password = 'foo')
)
system(command = paste0('unzip -P foo ', data.zip), 
  wait = TRUE
)
当我从我的第一次尝试中获取命令“
unzip-p-foo data.zip
”并从命令行运行它(添加了“
>data.sav
”)时,我得到了SPSS文件。所以有些东西起作用了。我的第三次尝试是使用连接:

file_connection <- getZip(url = '/path/to/data.zip', password = 'foo')
open(file_connection, 'rb')
data <- readBin(file_connection, raw())
close(file_connection)
所以。。。如何将受密码保护的zip存档中的
*.sav
文件成功解包并读取到R中

> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.4 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C                 
 [3] LC_TIME=en_US.UTF-8           LC_COLLATE=en_US.UTF-8       
 [5] LC_MONETARY=sv_SE.UTF-8       LC_MESSAGES=en_US.UTF-8      
 [7] LC_PAPER=sv_SE.UTF-8          LC_NAME=sv_SE.UTF-8          
 [9] LC_ADDRESS=sv_SE.UTF-8        LC_TELEPHONE=sv_SE.UTF-8     
[11] LC_MEASUREMENT=sv_SE.UTF-8    LC_IDENTIFICATION=sv_SE.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gmailr_0.7.1 rj_2.0.5-1  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.5         Formula_1.2-1       cluster_2.0.4      
 [4] magrittr_1.5        splines_3.3.0       munsell_0.4.3      
 [7] rj.gd_2.0.0-1       colorspace_1.2-6    lattice_0.20-33    
[10] R6_2.1.2            httr_1.1.0          plyr_1.8.3         
[13] tools_3.3.0         nnet_7.3-12         grid_3.3.0         
[16] data.table_1.9.6    gtable_0.2.0        latticeExtra_0.6-28
[19] openssl_0.9.3       survival_2.39-4     Matrix_1.2-6       
[22] gridExtra_2.2.1     RColorBrewer_1.1-2  ggplot2_2.1.0      
[25] base64enc_0.1-3     acepack_1.3-3.3     rpart_4.1-10       
[28] curl_0.9.7          scales_0.4.0        Hmisc_3.17-4       
[31] jsonlite_0.9.20     chron_2.3-47        foreign_0.8-66  
编辑:确定。所以我有一个(不那么优雅的)解决办法。我正在使用带有
wait=TRUE
参数的
system()
调用来解压缩文件。像这样:

data <- read.spss(getZip(url = '/path/to/data.zip', 
  password = 'foo')
)
system(command = paste0('unzip -P foo ', data.zip), 
  wait = TRUE
)
然后我可以将
*.sav
文件读入R。但是我仍然不知道如何使用
Hmisc::getZip()