| 1 |
#' Tidiers for NULL inputs |
| 2 |
#' |
| 3 |
#' `tidy(NULL)`, `glance(NULL)` and `augment(NULL)` all return an empty |
| 4 |
#' [tibble::tibble]. This empty tibble can be treated a tibble with zero |
| 5 |
#' rows, making it convenient to combine with other tibbles using |
| 6 |
#' functions like [purrr::map_df()] on lists of potentially `NULL` objects. |
| 7 |
#' |
| 8 |
#' @param x The value `NULL`. |
| 9 |
#' @param ... Additional arguments (not used). |
| 10 |
#' |
| 11 |
#' @return An empty [tibble::tibble]. |
| 12 |
#' |
| 13 |
#' @name null_tidiers |
| 14 |
#' @export |
| 15 |
#' @seealso [tibble::tibble] |
| 16 |
tidy.NULL <- function(x, ...) { |
| 17 |
tibble() |
| 18 |
} |
| 19 |
|
| 20 |
#' @rdname null_tidiers |
| 21 |
#' @export |
| 22 |
glance.NULL <- function(x, ...) tibble() |
| 23 |
|
| 24 |
#' @rdname null_tidiers |
| 25 |
#' @export |
| 26 |
augment.NULL <- function(x, ...) tibble() |
| 27 |
|
| 28 |
|
| 29 |
#' @export |
| 30 |
tidy.default <- function(x, ...) { |
| 31 |
cli::cli_abort("No {.fn tidy} method for objects of class {.cls {class(x)}}.") |
| 32 |
} |
| 33 |
|
| 34 |
#' @export |
| 35 |
glance.default <- function(x, ...) { |
| 36 |
cli::cli_abort( |
| 37 |
"No {.fn glance} method for objects of class {.cls {class(x)}}." |
| 38 |
) |
| 39 |
} |
| 40 |
|
| 41 |
#' @export |
| 42 |
augment.default <- function(x, ...) { |
| 43 |
cli::cli_abort( |
| 44 |
"No {.fn augment} method for objects of class {.cls {class(x)}}." |
| 45 |
) |
| 46 |
} |