r - 取消链接函数导致后续 `?` 和 `plot` 函数出错

标签 r osx-mavericks unzip

我正在使用 tempdir创建一个临时目录的函数,我在其中使用 unzip 提取 .zip 文件功能。与此相关,我认为最好删除临时目录以避免用废旧数据填满我的计算机。为此,我一直在使用 unlink功能。使用 unlink之前的功能 ?plot函数导致我的计算机出错(OS X Mavericks)。我还没有测试其他操作系统是否也是这种情况。我做了一些谷歌搜索,类似错误消息的一个理论是这个问题可能与加密硬盘有关。我的硬盘是加密的,所以可以匹配。但我不明白为什么会像 plot 那样重要。或 ?功能不应与 unlink 相关我心目中的操作。下面是一个例子:

location <- tempdir()
?plot
#works

unlink(location, recursive = TRUE)
?plot
# Error in file(out, "wt") : cannot open the connection

绘图适用于 R 中的警告,但不适用于 R Studio:
plot(1:10)
# Warning message:
# In file(out, "wt") :
# cannot open file #'/var/folders/wh/y62s7qxn29s2lvlx1nh9nxpr0000gq/T//RtmpdYlFVc/Rhttpd175551e9e35fa': No such file or # directory

这似乎适用于 R 工作室,但不适用于 R:
graphics.off()
?plot
# works again
plot(1:10)
# this works now too

这里发生了什么?如果问题与我的加密硬盘有关,是否有更简洁的方法来提取 .zip 文件而不生成废料数据?

附注。这是我的 session 信息(我在 R 版本 3.0.2 中遇到了同样的问题):
sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] devtools_1.4.1    roxygen2_3.0.0    gridExtra_0.9.1   data.table_1.8.10 xlsx_0.5.5        xlsxjars_0.5.0    rJava_0.9-6      
 [8] reshape2_1.2.2    ggplot2_0.9.3.1   plyr_1.8          Hmisc_3.13-0      Formula_1.1-1     survival_2.37-7   lattice_0.20-24  
[15] cluster_1.14.4   

loaded via a namespace (and not attached):
 [1] brew_1.0-6         codetools_0.2-8    colorspace_1.2-4   dichromat_2.0-0    digest_0.6.4       evaluate_0.5.1    
 [7] gtable_0.1.2       httr_0.2           labeling_0.2       MASS_7.3-29        memoise_0.1        munsell_0.4.2     
[13] parallel_3.0.3     proto_0.3-10       RColorBrewer_1.0-5 RCurl_1.95-4.1     scales_0.2.3       stringr_0.6.2     
[19] tools_3.0.3        whisker_0.3-2     

最佳答案

tempdir()是 R 的 session 范围临时工作目录,因此通过取消链接它,您已经删除了 R 用于各种临时文件的位置。你要tempfile() .返回值是一个临时路径,您可以在其中写入文件或创建目录,或者...

mydir <- tempfile()
basename(mydir) %in% dir(tempdir())   # FALSE
if (!dir.create(mydir))
    stop("failed to create my temporary directory")
basename(mydir) %in% dir(tempdir())   # TRUE
## ...
unlink(mydir, recursive=TRUE)
basename(mydir) %in% dir(tempdir())   # FALSE   

关于r - 取消链接函数导致后续 `?` 和 `plot` 函数出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22325820/

相关文章:

r - 行减法(A1-A2、A3-A4 等)

r - data.table 中的动态列名

python-2.7 - 在 Mavericks 上安装 gevent(Enthought Canopy python)

macos - Mac OS X 10.9 - 设置永久环境变量

r - (预)向函数工厂和内部提供变量

r - 按组将转置列突变为新列

macos - 如何在 Mac Mavericks 上永久停止 apache?

zip - 解压缩多部分文件 - 错误的 zipfile 偏移量(本地 header sig): 4

ios - Swift解压缩zip文件并从Gmail API的base64数据中查找xml文件

c - C 编程中的 Winzip 命令行