/
print.R
48 lines (44 loc) · 1.27 KB
/
print.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
#' Print a Data Package
#'
#' Prints a human-readable summary of a Data Package, including its resources
#' and a link to more information (if provided in `package$id`).
#'
#' @param x Data Package object, created with [read_package()] or
#' [create_package()].
#' @param ... Further arguments, they are ignored by this function.
#' @return [print()] with a summary of the Data Package object.
#' @family datapackage functions
#' @export
#' @examples
#' # Load the example Data Package
#' package <- example_package
#'
#' # Print a summary of the Data Package
#' package # Or print(package)
print.datapackage <- function(x, ...) {
# All prints should use cat (= cli::cat() helpers)
# List resources
resources <- resources(x)
cli::cat_line(
cli::format_inline(
"A Data Package with {length(resources)} resource{?s}{?./:/:}"
)
)
if (length(resources) > 0) {
cli::cat_bullet(resources, bullet = "bullet")
}
# Include link (DOI) if available in package$id
if (startsWith(x$id %||% "", "http")) {
cli::cat_line(
cli::format_inline("For more information, see {.url {x$id}}.")
)
}
# Provide help
cli::cat_line(
cli::format_inline(
"Use {.fun unclass} to print the Data Package as a list."
),
col = "silver"
)
invisible(x)
}