R/outputs.R

Defines functions outputs.WorkflowIdAndStatus outputs.character outputs

Documented in outputs outputs.character outputs.WorkflowIdAndStatus

#' Get the outputs for a workflow
#'
#' Retrieve the outputs for the specified workflow. Cromwell will return any
#' outputs which currently exist even if a workflow has not successfully
#' completed.
#'
#' @param x Cromwell API endpoint of \code{WorkflowIdAndStatus} object.
#' @param ... not used
#'
#' @return \code{WorkflowOutputs} object containing outputs and id.
#'
#' @examples
#' \dontrun{
#' host <- "http://localhost:8000"
#' workflow <- system.file("extdata/workflow.wdl", package = "CromwellClient")
#' inputs <- system.file("extdata/inputs.json", package = "CromwellClient")
#' job <- submit(host, workflow, inputs)
#' outputs(job)
#' }
#'
#' @rdname outputs
#' @export
outputs <- function(x, ...)
{
	UseMethod("outputs", x)
}

#' @param id A workflow ID.
#' @param version Cromwell API Version.
#'
#' @rdname outputs
#' @export
outputs.character <- function(x, id, version = "v1", ...)
{
	url <- file.path(x, "api/workflows", version, id, "outputs")

	response <- httr::GET(url, cromwellAgent())

	if (httr::http_error(response)) {
		stop(paste0("Cromwell API request failed.
Code: ", httr::status_code(response), "
Message: ", jsonlite::fromJSON(httr::content(response, "text"))$message), call. = FALSE)
	}

	if (httr::http_type(response) != "application/json") {
		stop("API did not return json", call. = FALSE)
	}

	content <- jsonlite::fromJSON(httr::content(response, "text"))
	structure(
		c(list(
			id = content$id,
			host = x,
			version = version
		), content$outputs),
		class = "WorkflowOutputs"
	)

}

#' @rdname outputs
#' @export
outputs.WorkflowIdAndStatus <- function(x, ...)
{
	outputs(x$host, id = x$id, version = x$version)
}
labbcb/CromwellClient documentation built on Aug. 16, 2020, 9:11 p.m.