Unlink function that causes an error for subsequent functions `?` And `plot`

I use the function tempdirto create a temporary directory where I extract the .zip files using the function unzip. In this regard, I found it advisable to delete temporary directories so as not to fill up my computer with recycling data. For this purpose I used a function unlink. Using functions unlinkbefore functions ?or plotcauses an error on my computer (OS X Mavericks). I did not check if this is the case for other operating systems. I did some search queries and one theory for a similar error message that this problem could be related to an encrypted hard drive. My hard drive is encrypted so that it can fit. But I do not understand why this is important, since functions plotor ?should not be associated with the operationunlink. Here is an example:

location <- tempdir()
?plot
#works

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

The job of working with a warning in R does not work in 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 is similar to working in studio R, but not in R:

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

What's going on here? If the problem is with my encrypted hard drive, is there an easier way to extract ZIP files without generating recycling data?

PS. Here is my session information (I had the same problem with R version 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     
+4
source share
1 answer

tempdir()is the session’s temporary working directory, so by canceling it you deleted the location that R uses for all kinds of temporary files. You want to tempfile(). The return value is a temporary path where you can 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   
+6
source

Source: https://habr.com/ru/post/1531160/


All Articles