Closed cynthiahqy closed 1 year ago
Drop tibble support for now
as_xmap_df <- as_xmap.data.frame
should always return a data.frame
for consistencyConsider in future:
as_xmap()
should return... tibble? data.frame?xmap_df
AND xmap_tbl
??? doesn't that just confuse things???as_xmap.tbl_df()
could use tidyselect? --- do I really want tidyselect?Code dump for tibble methods for later reference:
#' @describeIn new_xmap Construct xmap_tbl from tbl_df
new_xmap_tbl <- function(x = tibble::tibble(), col_from, col_to, col_weights, from_set = NULL) {
#' checks argument types
stopifnot(tibble::is_tibble(x))
#' coerce from xmap_df to xmap_tbl
x <- new_xmap_df(x, col_from, col_to, col_weights, from_set)
#' @return `x` with additional subclasses `xmap_tbl`, `xmap`
class(x) <- c("xmap_tbl", "xmap", "tbl_df", "tbl")
}
#' Print an `xmap_tbl`
#'
#' @export
print.xmap_tbl <- function(x){
xmap_df <- x
x_direction <- .get_link_direction.xmap_df(xmap_df)
x_type <- .get_link_types.xmap_df(xmap_df)
x_links <- tibble::as_tibble(xmap_df)
## print headers and links
cat(paste0("xmap_tbl:\n", x_type, "\n", x_direction, "\n"))
print(x_links)
}
What are the benefits to using the tibble class other than print methods?
Can a xmap_df
be passed to dplyr
functions, and does that convert it to a tibble?
Let the generic have the default: as_xmap(x, subclass = NULL)
, where subclass
can be _df
, _tbl
, _matrix
, _igraph
. So that:
<data.frame>
=> xmap_df
<tibble>
=> xmap_tbl
<matrix>
=> xmap_matrix
(probably want sparse matrix though)<igraph>
=> xmap_igraph
Need to implement separate
xmap_tbl
andxmap_df
to avoid inconsistency in return values. Currentlynew_xmap_df()
returns objects with 2 possible class attributes vectors:switch_xmap_df()
strips the tibble class attributes, butnew_xmap_df()
does not.