簡體   English   中英

解鏈接函數導致隨后的`?`和`plot`函數出錯

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

我正在使用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 studio,但不適用於R:

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

這里發生了什么? 如果問題與我的加密硬盤有關,是否有更簡潔的方法來提取.zip文件而不生成廢品數據?

PS。 這是我的會話信息(我在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的會話范圍的臨時工作目錄,因此通過取消鏈接,您刪除了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   

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM