-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathzzz.R
41 lines (37 loc) · 1013 Bytes
/
zzz.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
wm_GET <- function(url, query = list(), ...) {
cli <- crul::HttpClient$new(url = url, opts = list(...))
temp <- cli$get(query = query)
temp$raise_for_status()
if (temp$status_code == 204) {
stop(sprintf("(%s) %s", temp$status_code, temp$status_http()$message), call. = FALSE)
}
tmp <- jsonlite::fromJSON(temp$parse("UTF-8"), flatten = TRUE)
if (inherits(tmp, "data.frame")) {
tibble::as_data_frame(tmp)
} else if (inherits(tmp, "list")) {
if (all(sapply(tmp, class) == "data.frame")) {
lapply(tmp, tibble::as_data_frame)
} else {
tmp
}
} else {
tmp
}
}
wm_base <- function() "http://www.marinespecies.org/rest"
cc <- function(x) Filter(Negate(is.null), x)
as_log <- function(x) {
if (is.null(x)) {
x
} else {
if (x) "true" else "false"
}
}
assert <- function(x, y) {
if (!is.null(x)) {
if (!class(x) %in% y) {
stop(deparse(substitute(x)), " must be of class ",
paste0(y, collapse = ", "), call. = FALSE)
}
}
}