3

I am working intensively with the amazing ff and ffbase package. Due to some technical details, I have to work in my C: drive with my R session. After finishing that, I move the generated files to my P: drive (using cut/paste in windows, NOT using ff).

The problem is that when I load the ffdf object:

load.ffdf("data") 

I get the error:

Error: file.access(filename, 0) == 0 is not TRUE

This is ok, because nobody told the ffdf object that it was moved, but trying :

filename(data$x) <- "path/data_ff/x.ff"

or

pattern(data) <- "./data_ff/"

does not help, giving the error:

Error in `filename<-.ff`(`*tmp*`, value = filename) : 
ff file rename from 'C:/DATA/data_ff/id.ff' to 'P:/DATA_C/data_ff/e84282d4fb8.ff' failed. 

Is there any way to "change" into the ffdf object the path for the files new location? Thank you !!

4

2 回答 2

5

如果您想在之后“更正”您的文件名,您可以使用:

physical(x)$filename <- "newfilename"

例如:

> a <- ff(1:20, vmode="integer", filename="./a.ff")
> saveRDS(a, "a.RDS")
> rm(a)
> file.rename("./a.ff", "./b.ff")
[1] TRUE
> b <- readRDS("a.RDS")
> b
ff (deleted) integer length=20 (20)
> physical(b)$filename <- "./b.ff"
> b[]
opening ff ./b.ff
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20

在第一次会话中使用filename()当然会更容易。您还可以查看包中的save.ffdf相应load.ffdf函数ffbase,这使得这更加简单。

添加

要重命名 a 中所有列的文件名,ffdf可以使用以下函数:

redir <- function(ff, newdir) {
  for (x in physical(b)) {
    fn <- basename(filename(x))
    physical(x)$filename <- file.path(newdir, fn)
  }
  return (ff)
}
于 2013-07-04T10:06:44.303 回答
0

你也可以使用ff:::clone()

R> foo <- ff(1:20, vmode = "integer")
R> foo
ff (open) integer length=20 (20)
 [1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]      [13] [14] [15] [16] [17] [18] [19]
   1    2    3    4    5    6    7    8    :   13   14   15   16   17   18   19
[20]
  20
R> physical(foo)$filename
[1] "/vol/fftmp/ff69be3e90e728.ff"
R> bar <- clone(foo, pattern = "~/")
R> bar
ff (open) integer length=20 (20)
 [1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]      [13] [14] [15] [16] [17] [18] [19]
   1    2    3    4    5    6    7    8    :   13   14   15   16   17   18   19
[20]
  20
R> physical(bar)$filename
[1] "/home/ubuntu/69be5ec0cf98.ff"

根据我通过简要浏览 and 的代码所了解到的情况save.ffdfload.ffdf这些函数在您保存/加载时会为您执行此操作。

于 2013-07-04T13:39:21.520 回答