Debian Codegraph @

R/tbl-sum.R

raw
1 #' Provide a succinct summary of an object
2 #'
3 #' `tbl_sum()` gives a brief textual description of a table-like object,
4 #' which should include the dimensions and the data source in the first element,
5 #' and additional information in the other elements (such as grouping for \pkg{dplyr}).
6 #' The default implementation forwards to [pillar::obj_sum()].
7 #'
8 #' @return A named character vector, describing the dimensions in the first element
9 #' and the data source in the name of the first element.
10 #'
11 #' @examples
12 #' tbl_sum(1:10)
13 #' tbl_sum(matrix(1:10))
14 #' tbl_sum(data.frame(a = 1))
15 #' tbl_sum(Sys.Date())
16 #' tbl_sum(Sys.time())
17 #' tbl_sum(mean)
18 #'
19 #' @seealso [pillar::type_sum()]
20 #' @param x Object to summarise.
21 #' @export
22 tbl_sum <- function(x) {
23 UseMethod("tbl_sum", x)
24 }
25
26 #' @export
27 tbl_sum.default <- function(x) {
28 c("Description" = obj_sum(x))
29 }
30
31 #' @export
32 tbl_sum.tbl <- function(x) {
33 c("A data frame" = dim_desc(x))
34 }