How do I load a FIS response into an R object?

Home > Frequently Asked Questions > How do I load a FIS response into an R object?

You can use rjson R package and then convert the JSON object into an R object as in the following code snippets:


library("rjson")

loadFisResponse <- function(fisQuery) {
    return rjson::fromJSON(paste(readLines(fis_query), colapse = ""))
}

getDates <- function(fisResponse) {
    numberOfDates <- length(fisResponse[[1]])
    datesVector <- rep("", numberOfDates)
    for (listIndex in 1:numberOfDates) {
        datesVector[listIndex] <- fisResponse[[1]][[listIndex]]$date
    }
    return(datesVector)
}

makeHistogram <- function(fisResponse, itemIndex) {
    h <- fisResponse[[1]][[itemIndex]]$histogram
    numberOfBins <- length(h$bins)

    counts = rep(0, numberOfBins)
    values = rep(0, numberOfBins)
    for (i in 1:numberOfBins) {
        counts[i] <- h$bins[[i]]$count
        values[i] <- h$bins[[i]]$value
    }
    return(data.frame(values, counts))
}

getBasicStats <- function(fisResponse, itemIndex) {
    stats <- fisResponse[[1]][[itemIndex]]$basicStats
    minValue <- stats$min
    maxValue <- stats$max
    meanValue <- stats$mean
    standardDeviation <- stats$stDev
    return(data.frame(minValue, maxValue, meanValue, standardDeviation))
}

getNumberOfDates <- function(fisResponse) {
    return(length(fisResponse[[1]]))
}

The fisResponse object is expected to be a nested list that reflects the output format specified under FIS documentation.