Skip to content

Self-coercion of new class definition  #33

@justanna95

Description

@justanna95

Came across an issue when trying to row bind projectable columns of the same class that were created with the helper around new_col() along the lines of can't combine elements with different attributes. Fixed the issue by explicitly adding these helper functions where the new class was being defined.

# Helpers ----------------------------------------------------------------------
#' @export
#' @rdname col_median_ci
is_col_median_ci <- function(x) {
  inherits(x, "projectable_col_median_ci")
}

#' @export
`names<-.projectable_col_median_ci` <- function(x, value) {
  names(vctrs::field(x, "median")) <- value
  x
}

#' @export
names.projectable_col_median_ci <- function(x) {
  names(vctrs::field(x, "median"))
}

# Define coercion rules --------------------------------------------------------

# Self-coercion
#' @export
vec_ptype2.projectable_col_median_ci.projectable_col_median_ci <- function(x, y, ...) {
  new_col_median_ci()
}

# Define comparison rules ------------------------------------------------------

#' @export
vec_proxy_compare.projectable_col_median_ci <- function(x, ...) {
  vec_proxy_compare.projectable_col(x, ...)
}

I think only the coercion and comparison rules ones are required, but I haven't tested that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions