forked from ropensci/patentsview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.R
58 lines (49 loc) · 1.33 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
49
50
51
52
53
54
55
56
57
58
#' @export
print.pv_request <- function(x, ...) {
cat(
"#### An HTTP request where:\n\n",
"Method: ", x$method, "\n",
"URL: ", x$url,
ifelse("body" %in% names(x), paste0("\nBody: ", x$body), ""),
sep = ""
)
}
#' @export
print.pv_data_result <- function(x, ...) {
df <- x[[1]]
k <- vapply(names(df), function(y) class(df[, y]), FUN.VALUE = character(1))
lst <- ifelse("list" %in% k, " (with list column(s) inside) ", " ")
cat(
"#### A list with a single data frame", lst, "on ",
names(x)[1], " level:\n\n",
sep = ""
)
utils::str(
x, vec.len = 1, max.level = 2, give.attr = FALSE, strict.width = "cut",
formatNum = function(x, ...) {
format(x, trim = TRUE, drop0trailing = TRUE, scientific = FALSE, ...)
}
)
}
#' @export
print.pv_relay_db <- function(x, ...) {
utils::str(
x, vec.len = 1, max.level = 2, give.attr = FALSE, strict.width = "cut"
)
}
#' @export
print.pv_query_result <- function(x, ...) {
res_vec <- unlist(x)
cat(
"#### Distinct entity counts across all downloadable pages of output:\n\n",
paste0(names(res_vec), " = ", format_num(res_vec), collapse = ", "),
sep = ""
)
}
#' @export
print.pv_result <- function(x, ...) {
print(x[1])
print(x[2])
}
#' @export
print.pv_query <- function(x, ...) cat(jsonlite::toJSON(x, auto_unbox = TRUE))