简体   繁体   English

解链接函数导致随后的`?`和`plot`函数出错

[英]Unlink function causing an error for consequent `?` and `plot` functions

I am using tempdir function to create a temporary directory where I extract .zip files with unzip function. 我正在使用tempdir函数创建一个临时目录,我用unzip函数提取.zip文件。 In connection with this, I thought it's good to remove the temporary directories to avoid filling my computer up with scrap data. 与此相关,我认为删除临时目录以避免使用废料数据填满我的计算机是件好事。 For this purpose I have been using unlink function. 为此我一直在使用unlink功能。 Using unlink function before ? 之前使用unlink功能? or plot functions causes an error on my computer (OS X Mavericks). plot功能会导致计算机出错(OS X Mavericks)。 I have not tested whether this is the case for other operating systems. 我还没有测试其他操作系统是否属于这种情况。 I did some googling and one theory for similar error message was that this problem could be related to encrypted hard disc. 我做了一些谷歌搜索和一个类似的错误消息的理论是这个问题可能与加密的硬盘有关。 My hard disc is encrypted, so that could match. 我的硬盘已加密,因此可以匹配。 But I do not understand why should that matter as plot or ? 但是我不明白为什么这个问题应该是plot还是? functions should not be related to unlink operation in my mind. 函数不应该与我脑海中的unlink操作有关。 Here is an example: 这是一个例子:

location <- tempdir()
?plot
#works

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

Plotting works with a warning in R and does not work in R Studio: 绘图在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

This seems to work in R studio, but not in R: 这似乎适用于R studio,但不适用于R:

graphics.off()
?plot
# works again
plot(1:10)
# this works now too

What is going on here? 这里发生了什么? If the problem is related to my encrypted hard disc, is there a neater way extracting .zip files without generating scrap data? 如果问题与我的加密硬盘有关,是否有更简洁的方法来提取.zip文件而不生成废品数据?

PS. PS。 Here is my session information (I had the same problem with R version 3.0.2): 这是我的会话信息(我在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() is R's session-wide temporary working directory, so by unlinking it you've removed the location that R uses for all kinds of temporary files. tempdir()是R的会话范围的临时工作目录,因此通过取消链接,您删除了R用于各种临时文件的位置。 You want tempfile() . 你想要tempfile() The return value is a temporary path at which you could write a file or create a directory, or... 返回值是一个临时路径 ,您可以在其中编写文件或创建目录,或者......

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   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM