-
Notifications
You must be signed in to change notification settings - Fork 26
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 2 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,40 @@ | ||
#' Coercion methods for SOMA classes | ||
|
||
#' @importFrom arrow as_arrow_table | ||
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. Should we reexport #' @importFrom arrow as_arrow_table
#' @export
#'
arrow::as_arrow_table If not, these methods will be inaccessible to the end-user without |
||
#' @export | ||
as_arrow_table.SOMASparseNDArrayRead <- function(x){ | ||
x$tables()$concat() | ||
} | ||
|
||
#' Coerce \link[tiledbsoma]{SOMASparseNDArrayRead} to \link{data.frame} or \link[tibble]{tibble} | ||
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 mention the existence of these methods in the docs for SOMASparseNDArray but I don't think we should add a description here, which results in a separate documentation entry. |
||
#' @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") | ||
) | ||
|
||
#' @importFrom arrow as_arrow_table | ||
#' @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, ...) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ arrow_to_dt <- function(arrlst) { | |
} | ||
|
||
##' @noRd | ||
as_arrow_table <- function(arrlst) { | ||
to_arrow_table <- function(arrlst) { | ||
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. I could possibly make that simple list of two external pointers a simple S3 class (which I considered for the simple features like pretty printing). That may open the door for a dispatch of as_arrow_table.CLASSHERE as in your coercion utilities. Is that better? In the short term the renaming is fine but I do like these "verbs" to start with 'as' ... (We could also decide to make it 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.
Love this idea. Almost did it myself #1461 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. But @pablo-gar, note that I removed the internal 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. For correctness, let's add "proposing to remove 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.
Come to think about it, in |
||
check_arrow_pointers(arrlst) | ||
arrow::as_arrow_table(arrow::RecordBatch$import_from_c(arrlst[[1]], arrlst[[2]])) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Hm. Why would we need this now when we did not before?
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.
No, the
Collate
secion is not necessary. My guess is it was generated when@include
s were part of the code, then added as part of this PR