Kevin-Jin / mmap

Forked from https://r-forge.r-project.org/scm/?group_id=648
1 stars 1 forks source link

Attempt to allow mmap objects to be used as drop-in replacements for data.frame #7

Open Kevin-Jin opened 7 years ago

Kevin-Jin commented 7 years ago

Append data.frame to the vector of classes of the mmap object in as.mmap.data.frame(). This way, is.data.frame() returns true but S3 generic methods will execute the mmap override instead of the data.frame override.

Override `$`(x, i) operator to return NextMethod(i) if i %in% names(x) || !is.data.frame(x), and return `[[`(x, i) otherwise.

Override the 1D selection operator `[[`(x, i) to return NextMethod(i) if is.character(i) && i %in% names(x), and throw subscript out of bounds if is.data.frame(x) && (is.character(i) && !all(i %in% colnames(x)) || is.numeric(i) && i > x$dim[2]) || !is.data.frame(x) && is.numeric(i) && i > length(x) || i == 0, and return just column i otherwise (or cell i if !is.data.frame(x)).

Override the 2D selection operator `[[`(x, i, j) appropriately.

Change the 1D subset operator `[`(x, i, [...]) to throw undefined columns selected if is.data.frame(x) && (is.character(i) && !all(i %in% colnames(x)) || is.numeric(i) && i > x$dim[2]), and return NA if !is.data.frame(x) && is.numeric(i) && i > length(x), and return just columns i otherwise (or cells i if !is.data.frame(x)). Return an empty data.frame or vector to handle the value of 0 for i.

Change the 2D subset operator `[`(x, i, j, [...]) to throw undefined columns selected if is.character(i) && !all(i %in% colnames(x)) || is.numeric(i) && i > x$dim[2], and return .Call("mmap_extract", i, j, [...]) otherwise (as it currently does). Return an empty data.frame or vector to handle the value of 0 for i or j.

Override as.data.frame.mmap(x) to return NextMethod() if !is.data.frame(x), and return x unaltered otherwise.

Override as.list.mmap(x) to return NextMethod() if !is.data.frame(x), and return as.list(x[]) otherwise.

Override as.matrix.mmap(x) to return NextMethod() if !is.data.frame(x) && (is.null(x$dim) || length(x$dim) != 2), and return as.matrix(x[]) otherwise.

Kevin-Jin commented 7 years ago

Change length.mmap(x) to return length(x$storage.mode) if is.data.frame(x).

Kevin-Jin commented 7 years ago

Throw attempt to select more than one element if length(i) > 1 || length(j) > 1 in `[[`(x,i,j). Throw attempt to select less than one element if length(i)< 1 || length(j) < 1 in `[[`(x,i,j).

Kevin-Jin commented 7 years ago

Support drop parameter for `[`(x,i,j) and exact parameter for `[[`(x,i,j).

Kevin-Jin commented 7 years ago

Make sure `[[` drops names for matrices and data.frames while `[` keeps them.

Kevin-Jin commented 7 years ago

Add support for rbind() as long as the types match with the storage.mode.

Kevin-Jin commented 7 years ago

Support logical values for i and j. Also support nrow×2 numerical and character matrices for i when x is two dimensional or is a data.frame. See ?Extract.

Kevin-Jin commented 7 years ago

Fix problems with passing empty vectors for i or j to `[[`(x, i, j).