forked from tidyverse/dplyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprec-tibble.R
50 lines (42 loc) · 1.25 KB
/
deprec-tibble.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#' Coerce to a tibble
#'
#' \Sexpr[results=rd, stage=render]{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()")
# 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()")
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.
#'
#' \Sexpr[results=rd, stage=render]{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()")
abort_if_not(is.data.frame(df))
rn <- as_tibble(setNames(list(rownames(df)), var))
rownames(df) <- NULL
bind_cols(rn, df)
}