## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup, warning=FALSE, message = FALSE------------------------------------
library(propop)

# load package data
data("fso_parameters")
data("fso_population")

## ----project-canton-----------------------------------------------------------
projection_canton_2030 <- propop(
  parameters = fso_parameters,
  scenarios = "reference",
  year_first = 2026,
  year_last = 2030,
  population = fso_population,
  subregional = FALSE,
  binational = TRUE
)

projection_canton_2030 |>
  # round to 2 digits
  dplyr::mutate(across(n_jan:n_dec, \(x) sprintf(fmt = "%.0f", x))) |>
  DT::datatable(filter = "top") |>
  DT::formatStyle(
    "n_jan",
    backgroundColor = "#ffcc8f"
  ) |>
  DT::formatStyle(
    c("births", "mor_n", "emi_int_n", "emi_nat_n", "imm_int_n", "imm_nat_n", "acq_n"),
    backgroundColor = "#96D4FF"
  ) |>
  DT::formatStyle(
    "n_dec",
    backgroundColor = "#007AB8"
  )

## ----prepare-single-nationality-----------------------------------------------
fso_parameters_int <- fso_parameters |>
  # drop Swiss people, keep reference scenario
  dplyr::filter(nat == "int" & scen == "reference") |>
  #   remove `nat`, `acq` and `births_int_ch` from `parameters`
  dplyr::select(-c(nat, acq, int_mothers))

fso_population_int <- fso_population |>
  # drop Swiss people
  dplyr::filter(nat == "int") |>
  # remove `nat` from `population`
  dplyr::select(-nat)

## ----project-int--------------------------------------------------------------
projection_int <- propop(
  parameters = fso_parameters_int,
  scenarios = "reference",
  year_first = 2026,
  year_last = 2030,
  population = fso_population_int,
  subregional = FALSE,
  binational = FALSE
)

projection_int |>
  # round to two digits
  dplyr::mutate(across(n_jan:n_dec, \(x) sprintf(fmt = "%.0f", x))) |>
  DT::datatable(filter = "top")

