When a file is read with any of the read*StringSet()
functions, file handles are not closed. This prevents further operations on the file (e.g. deletion).
library(Biostrings)
fsource <- system.file(package="Biostrings", "extdata", "someORF.fa")
fdest <- basename(fsource)
file.copy(fsource, fdest, overwrite=TRUE)
# [1] TRUE
fseq <- readDNAStringSet(fdest)
file.remove(fdest)
# [1] FALSE
# Warning message:
# In file.remove(fdest) :
# cannot remove file 'someORF.fa', reason 'Permission denied'
Checking for open file handles results in the following:
Rgui.exe pid: 23312 type: File 384: C:\Users\xxx\Documents\someORF.fa
Rgui.exe pid: 23312 type: File 38C: C:\Users\xxx\Documents\someORF.fa
Through invoking gc()
, the open file handles are closed and the file can be deleted.
gc()
# used (Mb) gc trigger (Mb) max used (Mb)
# Ncells 2522803 134.8 5198228 277.7 2730967 145.9
# Vcells 4427580 33.8 10146329 77.5 6352280 48.5
file.remove(fdest)
# [1] TRUE
It would be helpful if this could be corrected in the upcoming Bioconductor release.
Environment:
R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)
locale:
[1] LC_COLLATE=English_Austria.utf8 LC_CTYPE=English_Austria.utf8
[3] LC_MONETARY=English_Austria.utf8 LC_NUMERIC=C
[5] LC_TIME=English_Austria.utf8
time zone: Europe/Vienna
tzcode source: internal
attached base packages:
[1] stats4 stats graphics grDevices utils datasets methods base
other attached packages:
[1] Biostrings_2.70.2 GenomeInfoDb_1.38.6 XVector_0.42.0 IRanges_2.36.0
[5] S4Vectors_0.40.2 BiocGenerics_0.48.1
loaded via a namespace (and not attached):
[1] zlibbioc_1.48.0 compiler_4.3.3 tools_4.3.3
[4] GenomeInfoDbData_1.2.11 RCurl_1.98-1.14 crayon_1.5.2
[7] bitops_1.0-7
Confirmed on windows. Not observed on my linux instance. In other words, the removal succeeds on linux.