Prepare data for Cadenza
Source:R/custom-serializer-enrichment-calculation.R
as_cadenza_enrichment_calculation.RdPrepare data for Cadenza
Usage
as_cadenza_enrichment_calculation(
data,
parameters = empty_named_list,
container_type = "text/csv",
...
)Arguments
- data
Either a dataframe or a list of either with data to send back to Cadenza.
- parameters
Parameters to return to Cadenza. Defaults to an empty named list.
- container_type
String: The HTML content type for serializing data. Defaults to
"text/csv". If data is a list, supply a vector with the content types for each element.- ...
For future expansion: Further arguments passed on to generating the metadata for the Cadenza response-
- role
A list of the same length as data with vectors of length
ncol(data[[el]]). Values"dimension"or"measure", indicating the role for Cadenza. Default values are"measure"for each column except IDs, Geometries or strings.
Value
List of class cadenza_response with elements metadata
and other elements passed in as dataargument.
Examples
data <- data.frame(a = rnorm(10L), b = runif(10L), c = letters[1L:10L])
# specify the container content type; this part will be serialized
# as JSON in the response.
as_cadenza_enrichment_calculation(data, container_type = "application/json")
#> $metadata
#> $metadata$parameters
#> named list()
#>
#> $metadata$dataContainers
#> $metadata$dataContainers[[1]]
#> $metadata$dataContainers[[1]]$type
#> [x] "application/json"
#>
#> $metadata$dataContainers[[1]]$name
#> [x] "data"
#>
#> $metadata$dataContainers[[1]]$columns
#> name printName attributeGroupName role dataType
#> 1 a a 1DIdTQhwBD measure float64
#> 2 b b 1DIdTQhwBD measure float64
#> 3 c c 1DIdTQhwBD dimension string
#>
#>
#>
#>
#> $data
#> a b c
#> 1 -1.400043517 0.28989230 a
#> 2 0.255317055 0.67838043 b
#> 3 -2.437263611 0.73531960 c
#> 4 -0.005571287 0.19595673 d
#> 5 0.621552721 0.98053967 e
#> 6 1.148411606 0.74152153 f
#> 7 -1.821817661 0.05144628 g
#> 8 -0.247325302 0.53021246 h
#> 9 -0.244199607 0.69582388 i
#> 10 -0.282705449 0.68855600 j
#>
#> attr(,"class")
#> [1] "cadenza_response" "list"
# List of data elements to return to Cadenza
data_list <- list(data, list(param = "a", vec = 1:13))
as_cadenza_enrichment_calculation(data_list,
container_type = c("text/csv", "application/json"))
#> $metadata
#> $metadata$parameters
#> named list()
#>
#> $metadata$dataContainers
#> $metadata$dataContainers[[1]]
#> $metadata$dataContainers[[1]]$type
#> [x] "text/csv"
#>
#> $metadata$dataContainers[[1]]$name
#> [x] "data_1"
#>
#> $metadata$dataContainers[[1]]$columns
#> name printName attributeGroupName role dataType
#> 1 a a gUde5llzyO measure float64
#> 2 b b gUde5llzyO measure float64
#> 3 c c gUde5llzyO dimension string
#>
#>
#> $metadata$dataContainers[[2]]
#> $metadata$dataContainers[[2]]$type
#> [x] "application/json"
#>
#> $metadata$dataContainers[[2]]$name
#> [x] "data_2"
#>
#> $metadata$dataContainers[[2]]$columns
#> name printName attributeGroupName role dataType
#> 1 param param SJAWUmCi4L dimension string
#> 2 vec vec SJAWUmCi4L measure int64
#>
#>
#>
#>
#> $data_1
#> a b c
#> 1 -1.400043517 0.28989230 a
#> 2 0.255317055 0.67838043 b
#> 3 -2.437263611 0.73531960 c
#> 4 -0.005571287 0.19595673 d
#> 5 0.621552721 0.98053967 e
#> 6 1.148411606 0.74152153 f
#> 7 -1.821817661 0.05144628 g
#> 8 -0.247325302 0.53021246 h
#> 9 -0.244199607 0.69582388 i
#> 10 -0.282705449 0.68855600 j
#>
#> $data_2
#> $data_2$param
#> [1] "a"
#>
#> $data_2$vec
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13
#>
#>
#> attr(,"class")
#> [1] "cadenza_response" "list"