Skip to content

Commit

Permalink
feat: add as_ijx() convenience function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed2uiz committed Jan 23, 2024
1 parent ee94247 commit 2352b6d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,22 @@ as_matrix <- function(x){
return(as.matrix(mat))
}
}

#' @title as_ijx
#' @param x dgCMatrix
#' @noRd
as_ijx <- function(x){
# check that x is a dgCMatrix
if(!inherits(x = x, what = "dgCMatrix")){
stop("Invalid input. Only dgCMatrix is currently supported.")
}

# Convert dgc into TsparseMatrix class from {Matrix}
ijx <- as(x, "TsparseMatrix")

# Get dbMatrix in triplet vector format (TSparseMatrix)
# Convert to 1-based indexing
df = data.frame(i = ijx@i + 1, j = ijx@j + 1, x = ijx@x)

return(df)
}

0 comments on commit 2352b6d

Please sign in to comment.