R/old_taxa--taxmap--s3.R

Defines functions get_dataset.Taxmap get_dataset.default get_dataset n_obs_1.Taxmap n_obs_1.default n_obs_1 n_obs.Taxmap n_obs.default n_obs sample_frac_obs.Taxmap sample_frac_obs.default sample_frac_obs sample_n_obs.Taxmap sample_n_obs.default sample_n_obs arrange_obs.Taxmap arrange_obs.default arrange_obs transmute_obs.Taxmap transmute_obs.default transmute_obs mutate_obs.Taxmap mutate_obs.default mutate_obs select_obs.Taxmap select_obs.default select_obs filter_obs.Taxmap filter_obs.default filter_obs obs_apply.Taxmap obs_apply.default obs_apply obs.Taxmap obs.default obs

Documented in arrange_obs filter_obs get_dataset mutate_obs n_obs n_obs_1 obs obs_apply sample_frac_obs sample_n_obs select_obs transmute_obs

# -----------------------------------------------------------------------------
#' @export
obs <- function(obj, data, value = NULL, subset = NULL, recursive = TRUE,
                simplify = FALSE) {
  UseMethod("obs")
}

#' @export
obs.default <- function(obj, data, value = NULL, subset = NULL, recursive = TRUE,
                        simplify = FALSE) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
obs.Taxmap <- function(obj, data, value = NULL, subset = NULL, recursive = TRUE,
                       simplify = FALSE) {
  obj <- eval(obj) # Needed by testthat for some reason
  eval(substitute(obj$obs(data, value = value, subset = subset, recursive = recursive,
                          simplify = simplify)))
}


# -----------------------------------------------------------------------------
#' @export
obs_apply <- function(obj, data, func, simplify = FALSE, value = NULL,
                      subset = NULL, recursive = TRUE, ...) {
  UseMethod("obs_apply")
}

#' @export
obs_apply.default <- function(obj, data, func, simplify = FALSE, value = NULL,
                              subset = NULL, recursive = TRUE, ...) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
obs_apply.Taxmap <- function(obj, data, func, simplify = FALSE, value = NULL,
                             subset = NULL, recursive = TRUE, ...) {
  obj <- eval(obj) # Needed by testthat for some reason
  eval(substitute(obj$obs_apply(data, func, simplify = simplify, value = value,
                                subset = subset, recursive = recursive, ...)))
}


# -----------------------------------------------------------------------------
#' @export
filter_obs <- function(obj, data, ..., drop_taxa = FALSE, drop_obs = TRUE,
                       subtaxa = FALSE, supertaxa = TRUE,
                       reassign_obs = FALSE, target = NULL) {
  UseMethod("filter_obs")
}

#' @export
filter_obs.default <- function(obj, data, ..., drop_taxa = FALSE, drop_obs = TRUE,
                               subtaxa = FALSE, supertaxa = TRUE,
                               reassign_obs = FALSE, target = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
filter_obs.Taxmap <- function(obj, data, ..., drop_taxa = FALSE, drop_obs = TRUE,
                              subtaxa = FALSE, supertaxa = TRUE,
                              reassign_obs = FALSE, target = NULL) {
  obj <- obj$clone(deep = TRUE)
  obj$filter_obs(data, ..., drop_taxa = drop_taxa, drop_obs = drop_obs,
                 subtaxa = subtaxa, supertaxa = supertaxa,
                 reassign_obs = reassign_obs, target = target)
}


# -----------------------------------------------------------------------------
#' @export
select_obs <- function(obj, data, ..., target = NULL) {
  UseMethod("select_obs")
}

#' @export
select_obs.default <- function(obj, data, ..., target = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
select_obs.Taxmap <- function(obj, data, ..., target = NULL) {
  obj <- obj$clone(deep = TRUE)
  obj$select_obs(data, ..., target = target)
}


# -----------------------------------------------------------------------------
#' @export
mutate_obs <- function(obj, data, ..., target = NULL) {
  UseMethod("mutate_obs")
}

#' @export
mutate_obs.default <- function(obj, data, ..., target = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
mutate_obs.Taxmap <- function(obj, data, ..., target = NULL) {
  obj <- obj$clone(deep = TRUE)
  obj$mutate_obs(data, ..., target = target)
}


# -----------------------------------------------------------------------------
#' @export
transmute_obs <- function(obj, data, ..., target = NULL) {
  UseMethod("transmute_obs")
}

#' @export
transmute_obs.default <- function(obj, data, ..., target = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
transmute_obs.Taxmap <- function(obj, data, ..., target = NULL) {
  obj <- obj$clone(deep = TRUE)
  obj$transmute_obs(data, ..., target = target)
}


# -----------------------------------------------------------------------------
#' @export
arrange_obs <- function(obj, data, ..., target = NULL) {
  UseMethod("arrange_obs")
}

#' @export
arrange_obs.default <- function(obj, data, ..., target = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
arrange_obs.Taxmap <- function(obj, data, ..., target = NULL) {
  obj <- obj$clone(deep = TRUE)
  obj$arrange_obs(data, ..., target = target)
}


# -----------------------------------------------------------------------------
#' @export
sample_n_obs <- function(obj, data, size, replace = FALSE, taxon_weight = NULL,
                         obs_weight = NULL, use_supertaxa = TRUE,
                         collapse_func = mean, ..., target = NULL) {
  UseMethod("sample_n_obs")
}

#' @export
sample_n_obs.default <- function(obj, data, size, replace = FALSE, taxon_weight = NULL,
                                 obs_weight = NULL, use_supertaxa = TRUE,
                                 collapse_func = mean, ..., target = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
sample_n_obs.Taxmap <- function(obj, data, size, replace = FALSE, taxon_weight = NULL,
                                obs_weight = NULL, use_supertaxa = TRUE,
                                collapse_func = mean, ..., target = NULL) {
  obj <- obj$clone(deep = TRUE)
  eval(substitute(obj$sample_n_obs(data, size, replace = replace, taxon_weight = taxon_weight,
                                   obs_weight = obs_weight, use_supertaxa = use_supertaxa,
                                   collapse_func = collapse_func, ..., target = target)))
}


# -----------------------------------------------------------------------------
#' @export
sample_frac_obs <- function(obj, data, size, replace = FALSE,
                            taxon_weight = NULL, obs_weight = NULL,
                            use_supertaxa = TRUE,
                            collapse_func = mean, ..., target = NULL) {
  UseMethod("sample_frac_obs")
}

#' @export
sample_frac_obs.default <- function(obj, data, size, replace = FALSE,
                                    taxon_weight = NULL, obs_weight = NULL,
                                    use_supertaxa = TRUE,
                                    collapse_func = mean, ..., target = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
sample_frac_obs.Taxmap <- function(obj, data, size, replace = FALSE,
                                   taxon_weight = NULL, obs_weight = NULL,
                                   use_supertaxa = TRUE,
                                   collapse_func = mean, ..., target = NULL) {
  obj <- obj$clone(deep = TRUE)
  eval(substitute(obj$sample_frac_obs(data, size, replace = replace,
                                      taxon_weight = taxon_weight, obs_weight = obs_weight,
                                      use_supertaxa = use_supertaxa,
                                      collapse_func = collapse_func, ..., target = target)))
}


# -----------------------------------------------------------------------------
#' @export
n_obs <- function(obj, data = NULL, target = NULL) {
  UseMethod("n_obs")
}

#' @export
n_obs.default <- function(obj, data = NULL, target = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
n_obs.Taxmap <- function(obj, data = NULL, target = NULL) {
  obj$n_obs(data = data, target = target)
}


# -----------------------------------------------------------------------------
#'@export
n_obs_1 <- function(obj, data = NULL, target = NULL) {
  UseMethod("n_obs_1")
}

#' @export
n_obs_1.default <- function(obj, data = NULL, target = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
n_obs_1.Taxmap <- function(obj, data = NULL, target = NULL) {
  obj$n_obs_1(data = data, target = target)
}


# -----------------------------------------------------------------------------
#'@export
get_dataset <- function(obj, data = NULL) {
  UseMethod("get_dataset")
}

#' @export
get_dataset.default <- function(obj, data = NULL) {
  stop("Unsupported class: ", class(obj)[[1L]], call. = FALSE, domain = NA)
}

#' @export
get_dataset.Taxmap <- function(obj, data = NULL) {
  obj$get_dataset(data = data)
}

Try the metacoder package in your browser

Any scripts or data that you put into this service are public.

metacoder documentation built on April 4, 2023, 9:08 a.m.