gpt4 book ai didi

r - 如何删除R中的ffdf对象目录?

转载 作者:行者123 更新时间:2023-12-02 04:27:05 26 4
gpt4 key购买 nike

我正在使用ffdf包进行一些数据预处理。我的工作计算机有 4 个 CPU 核心和 8 GB RAM,我可以处理大约 0.2-3 亿个数据点,这真的很棒。

但是,我还有另一个限制。大型 ffdf 对象耗尽了我计算机的磁盘空间。当我将 5 个表合并为一个表,并在其上添加 20 个以上的列时,我收到一条消息“没有磁盘空间”

所以,我想删除磁盘驱动器上未使用的 ffdf 对象。我可以在不退出 R session 的情况下执行此操作吗? (我对该文件夹具有读、写和执行权限。)

我已经尝试了我所知道的一切,例如unlink()file.remove()delete()close ()finalize()finalizer()ffdrop()”。

delete_dir <- "d:/ff/t1_pre"
deletephrase <- "t1_pre"
id <- grep(deletephrase, dir(delete_dir))
todelete <- dir(delete_dir, full.names=T)[id]
todelete
# [1] "d:/ff/t1_pre/t1_pre$b_cnt.ff" "d:/ff/t1_pre/t1_pre$b_rct.ff" "d:/ff/t1_pre/t1_pre$b_weit.ff"
# [4] "d:/ff/t1_pre/t1_pre$deal_id.ff" "d:/ff/t1_pre/t1_pre$m_id.ff" "d:/ff/t1_pre/t1_pre$saled_qty.ff"

unlink(todelete) #only delete .rdata and .rprofile

file.remove(todelete)
# [1] FALSE FALSE FALSE FALSE FALSE FALSE
# Warning messages:
# 1: In file.remove(todelete) :
# cannot remove file 'd:/ff/t1_pre/t1_pre$b_cnt.ff', reason 'Permission denied'
# 2: In file.remove(todelete) :
# cannot remove file 'd:/ff/t1_pre/t1_pre$b_rct.ff', reason 'Permission denied'
# 3: In file.remove(todelete) :
# cannot remove file 'd:/ff/t1_pre/t1_pre$b_weit.ff', reason 'Permission denied'
# 4: In file.remove(todelete) :
# cannot remove file 'd:/ff/t1_pre/t1_pre$deal_id.ff', reason 'Permission denied'
# 5: In file.remove(todelete) :
# cannot remove file 'd:/ff/t1_pre/t1_pre$m_id.ff', reason 'Permission denied'
# 6: In file.remove(todelete) :
# cannot remove file 'd:/ff/t1_pre/t1_pre$saled_qty.ff', reason 'Permission denied'

ffdrop("d:/ff/t2_pre/t2_pre$c_cnt.ff")
# $RData
# d:/ff/t2_pre/t2_pre$c_cnt.ff.RData
# FALSE

# $ffData
# d:/ff/t2_pre/t2_pre$c_cnt.ff.ffData
# FALSE

# Warning messages:
# 1: In file.remove(imgfile) :
# cannot remove file 'd:/ff/t2_pre/t2_pre$c_cnt.ff.RData', reason 'No such file or directory'
# 2: In file.remove(zipfile) :
# cannot remove file 'd:/ff/t2_pre/t2_pre$c_cnt.ff.ffData', reason 'No such file or directory'

finalize(t2_pre)
# $m_id
# [1] FALSE

# $deal_id
# [1] FALSE

close(t2_pre)
# [1] FALSE

finalizer(t2_pre)
# Error in UseMethod("finalizer") :
# no applicable method for 'finalizer' applied to an object of class "ffdf"

delete(t2_pre)
# [1] FALSE
# Warning messages:
# 1: In file.remove(attr(physical, "filename")) :
# cannot remove file 'd:/ff/t2_pre/t2_pre$m_id.ff', reason 'Permission denied'

最佳答案

您首先需要关闭 ff 文件,然后才能执行 file.remove。类似于 close(yourffdf)close(yourffobject) 和下一个 file.remove(list.files(yourpath), recursive=TRUE, full.names=TRUE ) 就可以了

require(ff)
x <- as.ffdf(iris)
sapply(filename(x), file.remove) ## Will fail
close(x)
sapply(filename(x), file.remove) ## Works

关于r - 如何删除R中的ffdf对象目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29504786/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com