R/spek_extractors.R

Defines functions get_id_col_from_spek get_value_or_numerator_col_from_spek get_column_names_by_use get_column_list get_name_of_column get_use_of_column

#' @title Spek Extractor Convenience Functions
#' @description Get the name of the id column in the data from the spek
get_id_col_from_spek <- function(spek) {
  column_list <- get_column_list(spek)
  column_names <- sapply(column_list, FUN=get_name_of_column)
  column_uses <- sapply(column_list, FUN=get_use_of_column)

  return(column_names[which(column_uses == "identifier")])
}

get_value_or_numerator_col_from_spek <- function(spek) {
  column_list <- get_column_list(spek)
  column_names <- sapply(column_list, FUN=get_name_of_column)
  column_uses <- sapply(column_list, FUN=get_use_of_column)

  return(column_names[which(column_uses == "value" | column_uses == "numerator")])
}

get_column_names_by_use <- function(spek, use){
  column_list <- get_column_list(spek)
  column_names <- sapply(column_list, FUN=get_name_of_column)
  column_uses <- sapply(column_list, FUN=get_use_of_column)

  return(column_names[which(column_uses == use)])
}

get_column_list <- function(spek) {
  spek[[PT$INPUT_TABLE_URI]][[1]][[PT$TABLE_SCHEMA_URI]][[1]][[PT$COLUMN_URI]]
}

get_name_of_column <- function(column_specification) {
  column_specification[[PT$COLUMN_NAME_URI]][[1]][['@value']]
}

get_use_of_column <- function(column_specification) {
  column_specification[[PT$COLUMN_USE_URI]][[1]][['@value']]
}
Display-Lab/pictoralist documentation built on April 1, 2020, 1:25 a.m.