-
Notifications
You must be signed in to change notification settings - Fork 0
/
rs_quality.R
74 lines (62 loc) · 1.73 KB
/
rs_quality.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#' List or translate AppEEARS quality metrics
#'
#' Returns a data frame of all quality layers,
#' or the translation of a quality layer value
#' into plain language.
#'
#' @param product AppEEARS product name
#' @param layer name of a product quality control layer
#' @param value quality control value to translate
#'
#' @return returns a data frame of all AppEEARS quality layers,
#' or those associated with a product. When a value is provided
#' this quality flag will be translated from bitwise representation
#' to plain language.
#'
#' @export
#' @author Koen Hufkens
#' @examples
#'
#' \dontrun{
#' # get a list of quality layers for all data products
#' rs_quality()
#'}
rs_quality <- memoise::memoise(function(
product,
layer,
value
){
# grab quality info for all products
if (
missing(product) &
missing(layer) &
missing(value)
){
ct <- httr::GET(
file.path(rs_server(),"quality"))
}
# grab quality info for a single product
if (!missing(product)) {
ct <- httr::GET(
file.path(rs_server(),"quality", product))
}
# grab quality info for a product layer combination
if (!missing(product) & !missing(layer)) {
ct <- httr::GET(
file.path(rs_server(),"quality", product, layer))
}
# grab quality info for a product layer combination
if (!missing(product) & !missing(layer) & !missing(value) ) {
ct <- httr::GET(
file.path(rs_server(),"quality", product, layer))
}
# split out the content from the returned
# API data, and clean up the JSON formatting
ct <- jsonlite::prettify(
jsonlite::toJSON(httr::content(ct), auto_unbox = TRUE)
)
# convert the json data to a data frame
df <- jsonlite::fromJSON(ct)
# return content
return(df)
})