R/ods_concepts.R

Defines functions ods_concepts

#' List all unique concepts of a dataset scheme
#'
#' \code{ods_concepts} is an internal function for \code{ods_dataset} that returns all unique values of a dataset scheme
#'
#' @param dataset \code{string}. The identifying final part of a URI for a dataset on \href{https://statistics.gov.scot/}{statistics.gov.scot}.
#' @param scheme \code{string}. The desired scheme of the dataset named in the dataset argument.
#'
#' @return \code{data.frame}.
#'
#' @examples
#' ods_concepts("average-household-size", "<http://purl.org/linked-data/sdmx/2009/dimension#refArea>")
#'
#' @keywords internal
#'
#' @noRd

ods_concepts <- function(dataset, scheme, labelled = FALSE) {

  endpoint <- "http://statistics.gov.scot/sparql"

    if(labelled){
      query_file <- "concepts"
    } else{
      query_file <- "concepts_raw"
    }
    query_text <- read_query_file(query_file)
  
  query_text <- read_query_file("concepts")
  query <- glue::glue(query_text, dataset = dataset, scheme = scheme, .open = "[", .close = "]")
  query_data <- ods_query_database(endpoint, query)
  result <- pre_process_data(query_data)$concept




  return(result)
}
jsphdms/scotgov documentation built on Oct. 16, 2024, 6 p.m.