-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[r] Implement as
generics for SOMASparseNDArrayReader
#1458
base: main
Are you sure you want to change the base?
Changes from all commits
5f8d902
ff657d8
de2f496
458f453
9754d69
ca0593a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#' Coercion methods for SOMA classes | ||
|
||
# Set R6 methods formally as S3 to create apply generics | ||
methods::setOldClass("SOMASparseNDArrayRead") | ||
methods::setOldClass("TableReadIter") | ||
|
||
#' @importClassesFrom Matrix TsparseMatrix CsparseMatrix RsparseMatrix | ||
NULL | ||
|
||
#' @importFrom arrow as_arrow_table | ||
#' @export | ||
arrow::as_arrow_table | ||
|
||
|
||
#' @importFrom arrow as_arrow_table | ||
#' @export | ||
as_arrow_table.SOMASparseNDArrayRead <- function(x){ | ||
x$tables()$concat() | ||
} | ||
|
||
#' @export | ||
as.data.frame.SOMASparseNDArrayRead <- function(x, ...){ | ||
as.data.frame(x$tables()$concat(), ...) | ||
} | ||
|
||
# Coerce \link[tiledbsoma]{SOMASparseNDArrayRead} to Matrix::\link[Matrix]{dgTMatrix} | ||
setAs(from = "SOMASparseNDArrayRead", | ||
to = "TsparseMatrix", | ||
def = function(from) from$sparse_matrix()$concat() | ||
) | ||
Comment on lines
+26
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The R6 classes may need to be declared as an old class with methods::setOldClass("SOMASparseNDArrayRead") We may also need to import the target classes from Matrix #' @importClassesFrom Matrix TsparseMatrix CsparseMatrix RsparseMatrix
#'
NULL |
||
|
||
# Coerce \link[tiledbsoma]{SOMASparseNDArrayRead} to Matrix::\link[Matrix]{dgCMatrix} | ||
setAs(from = "SOMASparseNDArrayRead", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also provide a delayed method for #' @exportS3Method SeuratObject::as.sparse
#'
as.sparse.SOMASparseNDArrayRead <- function(x, ...) {
as(x, "CsparseMatrix")
} |
||
to = "CsparseMatrix", | ||
def = function(from) as(as(from, "TsparseMatrix"), "CsparseMatrix") | ||
) | ||
|
||
# Coerce \link[tiledbsoma]{SOMASparseNDArrayRead} to Matrix::\link[Matrix]{dgRMatrix} | ||
setAs(from = "SOMASparseNDArrayRead", | ||
to = "RsparseMatrix", | ||
def = function(from) as(as(from, "TsparseMatrix"), "RsparseMatrix") | ||
) | ||
|
||
#' @export | ||
as_arrow_table.TableReadIter <- function(x) x$concat() | ||
|
||
#' @export | ||
as.data.frame.TableReadIter <- function(x, row.names = NULL, optional = FALSE, ...){ | ||
as.data.frame(x$concat(), row.names = row.names, optional = optional, ...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we reexport
as_arrow_table
?If not, these methods will be inaccessible to the end-user without
library(arrow)
first