Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
213 lines (146 sloc) 3.26 KB
#' @name snake
#'
#' @inherit bioverbs::snake
#' @inherit camel return
#' @inheritParams params
#'
#' @examples
#' data(mn, package = "acidtest")
#' lapply(mn, snake)
NULL
#' @importFrom bioverbs snake
#' @aliases NULL
#' @export
bioverbs::snake
.snake <- # nolint
function(object) {
object <- dotted(object)
object <- tolower(object)
object <- gsub(pattern = "\\.", replacement = "_", x = object)
object
}
snake.ANY <- # nolint
function(object) {
if (hasNames(object)) {
names(object) <- .snake(names(object))
}
object
}
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("ANY"),
definition = snake.ANY
)
snake.character <- # nolint
function(object) {
if (hasNames(object)) {
names <- .snake(names(object))
} else {
names <- NULL
}
object <- .snake(object)
names(object) <- names
object
}
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("character"),
definition = snake.character
)
snake.factor <- # nolint
function(object) {
names <- names(object)
object <- as.character(object)
object <- snake(object)
object <- as.factor(object)
names(object) <- snake(names)
object
}
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("factor"),
definition = snake.factor
)
snake.matrix <- # nolint
function(
object,
rownames = FALSE,
colnames = TRUE
) {
assert(
hasDimnames(object),
isFlag(rownames)
)
if (isTRUE(rownames) && hasRownames(object)) {
rownames(object) <- snake.character(rownames(object))
}
if (isTRUE(colnames) && hasColnames(object)) {
colnames(object) <- snake.character(colnames(object))
}
object
}
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("matrix"),
definition = snake.matrix
)
snake.Matrix <- snake.matrix # nolint
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("Matrix"),
definition = snake.Matrix
)
snake.data.frame <- snake.matrix # nolint
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("data.frame"),
definition = snake.data.frame
)
snake.DataFrame <- snake.data.frame # nolint
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("DataFrame"),
definition = snake.DataFrame
)
snake.GRanges <- # nolint
function(object) {
colnames(mcols(object)) <- snake(colnames(mcols(object)))
object
}
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("GRanges"),
definition = snake.GRanges
)
snake.GRangesList <- snake.GRanges # nolint
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("GRangesList"),
definition = snake.GRangesList
)
snake.SummarizedExperiment <- snake.matrix # nolint
#' @rdname snake
#' @export
setMethod(
f = "snake",
signature = signature("SummarizedExperiment"),
definition = snake.SummarizedExperiment
)
You can’t perform that action at this time.