r不会删除我用h5包打开的文件

m2xkgtsf  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(215)

我有一个文件夹完整的压缩hdf5文件。我想创建一个脚本来循环遍历每个文件,解压,读取hdf5文件的某些元素,然后删除解压后的文件。
我有问题,因为r将不会删除hdfs文件,给一个权限错误。我已经使用适当的命令关闭了对hdf5文件的引用,该命令返回true,但是只有在重新启动rsession之后才能删除该文件。
举个例子,

library(h5)

# create an example hdf5 file

file <- h5file("test.hdf5", 'w')

# create some example data.

testvec <- rnorm(10)
testmat <- matrix(1:9, nrow = 3)
row.names(testmat) <- 1:3
colnames(testmat) <- c("A", "BE", "BU")
letters1 <- paste(LETTERS[runif(45, min = 1, max = length(LETTERS))])
letters2 <- paste(LETTERS[runif(45, min = 1, max = length(LETTERS))])
testarray <- array(paste0(letters1, letters2), c(3, 3, 5))

# write the data to hdf5 file

file["test/testvec"] <- testvec
file["test/testmat"] <- testmat
file["test/testarray"] <- testarray

# close the file reference

closed <- h5close(file)
cat(sprintf('Closed the example file = %i\n', closed))

openedFromDisk <- h5file("test.hdf5")
thedata <- readDataSet(openedFromDisk["test/testarray"])
closed <- h5close(openedFromDisk)
cat(sprintf('Closed the loaded file = %i\n', closed))

# attempt to delete the file

removed <- file.remove("test.hdf5")
cat(sprintf('Deleted the loaded file = %i\n', removed))

这就像r或h5包在锁定文件,即使close命令返回true。有人知道我该怎么纠正吗?我需要删除未压缩的文件,因为我有几千个大文件要处理,我的硬盘不够大。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题