This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathbomrang_tbl.R
50 lines (48 loc) · 1.69 KB
/
bomrang_tbl.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
#' @export
#' @noRd
print.bomrang_tbl <- function(x, ...) {
.bomrang_header(x)
print(data.table::as.data.table(x), ...)
}
.bomrang_header <- function(x) {
location <- attr(x, "location") %||% "UNKNOWN"
station <- attr(x, "station") %||% "UNKNOWN"
lat <- attr(x, "lat") %||% "UNKNOWN"
lon <- attr(x, "lon") %||% "UNKNOWN"
type <- tools::toTitleCase(attr(x, "type")) %||% "UNKNOWN"
origin <- tools::toTitleCase(attr(x, "origin")) %||% "UNKNOWN"
start <- attr(x, "start") %||% "UNKNOWN"
end <- attr(x, "end") %||% "UNKNOWN"
count <- attr(x, "count") %||% "UNKNOWN"
units <- attr(x, "units") %||% NULL
vars <- attr(x, "vars") %||% "UNKNOWN"
indices <- attr(x, "indices") %||% "UNKNOWN"
.stylecat(" --- Australian Bureau of Meteorology (BOM) Data Resource ---\n")
.stylecat(" (Original Request Parameters)\n")
.stylecat(" Station:\t\t", location, " [", station, "] \n")
.stylecat(" Location:\t\t", "lat: ", lat, ", lon: ", lon, "\n")
.stylecat(" Measurement / Origin:\t", type, " / ", origin, "\n")
.stylecat(" Timespan:\t\t",
start,
" -- ",
end,
" [",
count,
" ",
units,
"]",
"\n")
# dplyr groupings
if (!is.null(attr(x, "vars"))) {
.stylecat(" Groups:\t\t", vars, paste0(" [", length(indices), "]\n"))
}
if (!is.null(attr(x, "groups"))) {
vars <- setdiff(names(attr(x, "groups")), ".rows")
indices <- nrow(attr(x, "groups"))
.stylecat(" Groups:\t\t", vars, paste0(" [", indices, "]\n"))
}
.stylecat(" ", strrep("-", 63), " \n")
}
.stylecat <- function(...) {
cat(crayon::cyan(crayon::italic(paste0(...))))
}