R/deprec-tibble.R

Defines functions add_rownames as.tbl.data.frame as.tbl.tbl as.tbl tbl_df

Documented in add_rownames as.tbl tbl_df

#' Coerce to a tibble
#'
#' `r lifecycle::badge("deprecated")`
#' Please use [tibble::as_tibble()] instead.
#'
#' @export
#' @keywords internal
#' @param data,x Object to coerce
tbl_df <- function(data) {
  lifecycle::deprecate_warn("1.0.0", "tbl_df()", "tibble::as_tibble()", always = TRUE)
  # Works in tibble < 1.5.0 too, because .name_repair will be
  # swallowed by the ellipsis
  as_tibble(data, .name_repair = "check_unique")
}

#' @export
#' @rdname tbl_df
as.tbl <- function(x, ...) {
  lifecycle::deprecate_warn("1.0.0", "as.tbl()", "tibble::as_tibble()", always = TRUE)
  UseMethod("as.tbl")
}

#' @export
as.tbl.tbl <- function(x, ...) x

#' @export
as.tbl.data.frame <- function(x, ...) {
  as_tibble(x)
}


#' Convert row names to an explicit variable.
#'
#' `r lifecycle::badge("deprecated")`
#' Please use [tibble::rownames_to_column()] instead.
#'
#' @param df Input data frame with rownames.
#' @param var Name of variable to use
#' @keywords internal
#' @export
add_rownames <- function(df, var = "rowname") {
  lifecycle::deprecate_warn("1.0.0", "add_rownames()", "tibble::rownames_to_column()", always = TRUE)

  stopifnot(is.data.frame(df))

  rn <- as_tibble(setNames(list(rownames(df)), var))
  rownames(df) <- NULL

  bind_cols(rn, df)
}
hadley/dplyr documentation built on Nov. 6, 2024, 4:48 p.m.