## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 10, fig.height = 8)
library(pcatR)

## -----------------------------------------------------------------------------
pcat_items("both")
pcat_construct_map("2022", include_secondary = TRUE)
pcat_response_options()

## -----------------------------------------------------------------------------
dat <- pcat_example_data()
analysis <- pcat_analyse(
  dat,
  group_vars = c("site_id", "timepoint"),
  require_complete = TRUE,
  validation_action = "none"
)
analysis

## -----------------------------------------------------------------------------
pcat_validation_issues(analysis$validation)
head(analysis$summary)
head(analysis$consensus)

## ----fig.height=10, fig.alt="Diverging pCAT item profiles comparing barrier and facilitator response shares at planning and mid-implementation."----
plot_pcat_profile(
  analysis$classified,
  group_vars = "timepoint",
  label = "cfir_original_construct"
)

## -----------------------------------------------------------------------------
change <- pcat_change(
  analysis$classified,
  from = "planning",
  to = "mid_implementation"
)
head(change)

## ----eval=FALSE---------------------------------------------------------------
# output_dir <- tempfile("pcat_analysis_", tmpdir = tempdir())
# 
# pcat_write_analysis(
#   analysis,
#   path = output_dir,
#   overwrite = TRUE
# )
# 
# unlink(output_dir, recursive = TRUE, force = TRUE)

