knitr::opts_chunk$set(
  warning = TRUE,
  message = TRUE,
  error = TRUE, 
  echo = FALSE
)
pander::panderOptions("table.split.table", Inf)
library(codebook)
library(jGBV)
ggplot2::theme_set(ggplot2::theme_bw())

Codebook for data collected from administration of survey questionnaire:

State: r params$state Sector or Tool type: r params$toolType

raampDir <- make_dir_tree()
stateFpath <- .removeSpaceForFilepath(params$state)

codebook_data <- readRDS(file.path(
    raampDir$quant,
    stateFpath,
    sprintf(
      "fullyLabelledData__%s_%s.rds",
      stateFpath,
      params$toolType
    )
  ))

codebook_data <- detect_missing(
  codebook_data,
  only_labelled = TRUE,
  negative_values_are_missing = FALSE,
  ninety_nine_problems = TRUE,
)

# codebook_data <- detect_scales(codebook_data)
# For integer values labelled with HMisc::label(), there was a problem
# handling missing values recorded as NA, but when converted to NA_integer_,
# the issue resolves.  A loop is used to ensure the preservation of attributes.
# See https://github.com/rubenarslan/codebook/issues/45)
for(i in seq_len(ncol(codebook_data))) {
  cb <- codebook_data[, i]
  if (identical(class(cb), c("labelled", "integer"))) {
    cb <- ifelse(is.na(cb), NA_integer_, cb)
  }
  codebook_data[, i] <- cb
}

codebook(codebook_data)


BroVic/jGBV documentation built on Oct. 9, 2022, 6:38 a.m.