From 56f92a1539fbbe4d8e773ad5ab28298f3be4e033 Mon Sep 17 00:00:00 2001 From: George Chen <72078254+jiajic@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:17:38 -0400 Subject: [PATCH] fix: dimnames/colnames generics --- R/join.R | 1 - R/methods-names.R | 28 +++++++++++++++++++++++++++- R/methods-rbind.R | 2 +- man/dimnames.Rd | 12 ++++++++++++ man/row-plus-colnames-generic.Rd | 4 ++++ 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/R/join.R b/R/join.R index 5dcd4674..c6e2a4d3 100644 --- a/R/join.R +++ b/R/join.R @@ -686,7 +686,6 @@ joinGiottoObjects <- function(gobject_list, - ## spatial locations vmsg(.v = verbose, "3. spatial locations") diff --git a/R/methods-names.R b/R/methods-names.R index bbb9d7af..0cb6a215 100644 --- a/R/methods-names.R +++ b/R/methods-names.R @@ -1,12 +1,17 @@ #' @include generics.R NULL +# NOTE: +# dimnames MUST be provided for rownames and colnames methods to be well +# behaved + #' @title Row and column names #' @name row-plus-colnames-generic #' @aliases colnames rownames #' @description Retrieve or set the row or column names of an object #' @param x object #' @return A character vector of row or col names +#' @keywords internal #' @examples #' g <- GiottoData::loadSubObjectMini("exprObj") #' @@ -19,6 +24,7 @@ NULL #' Retrieve or set the dimnames of an object #' @param x object #' @returns character +#' @keywords internal #' @examples #' g <- GiottoData::loadSubObjectMini("exprObj") #' @@ -60,7 +66,9 @@ setMethod("rownames", signature(x = "exprObj"), function(x) rownames(x[])) #' @export setMethod("rownames", signature(x = "dimObj"), function(x) rownames(x[])) - +#' @rdname row-plus-colnames-generic +#' @export +setMethod("rownames", signature(x = "metaData"), function(x) rownames(x[])) @@ -71,3 +79,21 @@ setMethod("dimnames", signature(x = "exprObj"), function(x) dimnames(x[])) #' @rdname dimnames #' @export setMethod("dimnames", signature(x = "dimObj"), function(x) dimnames(x[])) + +#' @rdname dimnames +#' @export +setMethod("dimnames", signature(x = "spatLocsObj"), function(x) dimnames(x[])) + +#' @rdname dimnames +#' @export +setMethod("dimnames", signature(x = "metaData"), function(x) dimnames(x[])) + +#' @rdname dimnames +#' @export +setMethod("dimnames", signature(x = "enrData"), function(x) dimnames(x[])) + +#' @rdname dimnames +#' @export +setMethod("dimnames", signature(x = "dimObj"), function(x) dimnames(x[])) + + diff --git a/R/methods-rbind.R b/R/methods-rbind.R index a3b2c71f..dcd08031 100644 --- a/R/methods-rbind.R +++ b/R/methods-rbind.R @@ -33,7 +33,7 @@ setMethod( stop("rbind: `spatLocsObj` with the same IDs cannot be joined", call. = FALSE) } - + # if one is 3d, ensure both are 3d x3 <- .is_3d_spatlocs(x) y3 <- .is_3d_spatlocs(y) diff --git a/man/dimnames.Rd b/man/dimnames.Rd index 0be71b51..dcad2fc1 100644 --- a/man/dimnames.Rd +++ b/man/dimnames.Rd @@ -4,10 +4,21 @@ \alias{dimnames} \alias{dimnames,exprObj-method} \alias{dimnames,dimObj-method} +\alias{dimnames,spatLocsObj-method} +\alias{dimnames,metaData-method} +\alias{dimnames,enrData-method} \title{Dimnames of an object} \usage{ \S4method{dimnames}{exprObj}(x) +\S4method{dimnames}{dimObj}(x) + +\S4method{dimnames}{spatLocsObj}(x) + +\S4method{dimnames}{metaData}(x) + +\S4method{dimnames}{enrData}(x) + \S4method{dimnames}{dimObj}(x) } \arguments{ @@ -24,3 +35,4 @@ g <- GiottoData::loadSubObjectMini("exprObj") dimnames(g) } +\keyword{internal} diff --git a/man/row-plus-colnames-generic.Rd b/man/row-plus-colnames-generic.Rd index ba9cf466..6bbd5a91 100644 --- a/man/row-plus-colnames-generic.Rd +++ b/man/row-plus-colnames-generic.Rd @@ -12,6 +12,7 @@ \alias{colnames,dimObj-method} \alias{rownames,exprObj-method} \alias{rownames,dimObj-method} +\alias{rownames,metaData-method} \title{Row and column names} \usage{ \S4method{colnames}{exprObj}(x) @@ -29,6 +30,8 @@ \S4method{rownames}{exprObj}(x) \S4method{rownames}{dimObj}(x) + +\S4method{rownames}{metaData}(x) } \arguments{ \item{x}{object} @@ -44,3 +47,4 @@ g <- GiottoData::loadSubObjectMini("exprObj") colnames(g) } +\keyword{internal}