% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/target-import.R
\name{wf_import_target}
\alias{wf_import_target}
\title{Import a verified external population target}
\usage{
wf_import_target(
  data_file,
  source_file,
  dims,
  key_map,
  count,
  by = NULL,
  by_key = NULL,
  production = TRUE
)
}
\arguments{
\item{data_file}{Path to a CSV or XLSX population table.}

\item{source_file}{Path to its companion source DCF record.}

\item{dims}{A \code{wf_dims} object.}

\item{key_map}{Named mapping from dimensions to data columns.}

\item{count}{Name of the population-count column.}

\item{by}{Optional grouping variable.}

\item{by_key}{Optional group-key column or function.}

\item{production}{Whether to reject demo-only sources.}
}
\value{
A \code{wf_verified_target} object.
}
\description{
Imports CSV or Excel population margins only when a companion DCF record
supplies complete provenance and a matching SHA-256 checksum.
}
\examples{
# WFC ships a synthetic demo target beside its companion evidence record.
csv_file <- system.file(
  "extdata", "safe-target-example.csv",
  package = "WFC"
)
csv_source <- paste0(csv_file, ".source.dcf")

dims_safe <- wf_dims(sex = c("F", "M"), age = c("18-34", "35+"))

# `production = FALSE` is required here only because the bundled file is
# declared demo-only. Do not use it to admit an authoritative source whose
# evidence record is incomplete.
target <- wf_import_target(
  csv_file,
  csv_source,
  dims_safe,
  key_map = c(sex = "sex", age = "age"),
  count = "count",
  production = FALSE
)
target$identity

# The same demo file is refused as a production source, so a synthetic
# file cannot impersonate an authoritative population.
try(wf_import_target(
  csv_file,
  csv_source,
  dims_safe,
  key_map = c(sex = "sex", age = "age"),
  count = "count"
))
}
