forked from CIP-RIU/brapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathba_trials_details.R
50 lines (49 loc) · 1.82 KB
/
ba_trials_details.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
#' ba_trials_details
#'
#' List trial summary details for a given trial database identifier.
#'
#' @param con list, brapi connection object
#' @param trialDbId character, the internal database identifier for a trial of
#' which the summary details are to be retreived; \strong{REQUIRED
#' ARGUMENT} with default: ""
#' @param rclass character, class of the object to be returned; default: "tibble"
#' , possible other values: "json"/"list"/"data.frame"
#'
#' @return An object of class as defined by rclass containing the trial summary
#' details.
#'
#' @note Tested against: sweetpotatobase, test-server
#' @note BrAPI Version: 1.0, 1.1, 1.2
#' @note BrAPI Status: active
#'
#' @author Reinhard Simon, Maikel Verouden
#' @references \url{https://github.com/plantbreeding/API/blob/V1.2/Specification/Trials/GetTrialById.md}(github)
#' @family trials
#' @family phenotyping
#' @example inst/examples/ex-ba_trials_details.R
#' @import tibble
#' @export
ba_trials_details <- function(con = NULL,
trialDbId = "",
rclass = c("tibble", "data.frame",
"list", "json")) {
ba_check(con = con, verbose = FALSE, brapi_calls = "trials/id")
check_character(trialDbId)
rclass <- match.arg(rclass)
brp <- get_brapi(con = con)
callurl <- paste0(brp, "trials/", trialDbId)
try({
resp <- brapiGET(url = callurl, con = con)
cont <- httr::content(x = resp, as = "text", encoding = "UTF-8")
out <- NULL
if (rclass %in% c("list", "json")) {
out <- dat2tbl(res = cont, rclass = rclass)
}
if (rclass %in% c("data.frame", "tibble")) {
out <- trld2tbl2(res = cont, rclass = rclass)
}
class(out) <- c(class(out), "ba_trials_details")
show_metadata(resp)
return(out)
})
}