Skip to contents

Bind observations to their collection context

Usage

studyframe(
  data,
  keys,
  unit,
  dataset_id,
  version = "",
  author = "",
  notes = "",
  variables = list(),
  sampling = list(),
  weights = list(),
  assignments = list(),
  roster = roster_spec(),
  evidence = list(),
  diagnostics = list()
)

Arguments

data

A data.frame of primitive columns. Factors, dates, list columns, infinities, and NaN must be converted explicitly before construction.

keys

Character vector of stable variable identifiers uniquely identifying rows.

unit

Description of the observational unit.

dataset_id

Dataset identifier.

version

Dataset version (distinct from the schema version).

author

Responsible person or organization.

notes

Free-text context.

variables

List of variable_spec declarations. Undeclared columns receive an unknown definition. IDs default to column names and must be syntactic identifiers.

sampling

List of sampling_spec declarations.

weights

List of weight_spec declarations.

assignments

List of assignment_spec declarations.

roster

A roster_spec. Ordinary imports default to unknown completeness.

evidence

List of evidence_spec source records.

diagnostics

List of analysis_issue records retaining import uncertainty.

Value

A studyframe inheriting from data.frame, with its original roster attached.

Examples

x <- studyframe(data.frame(id = 1:3, income = c(10, 20, 30)),
  keys = "id", unit = "person", dataset_id = "example"
)
x[c(3, 1), ]
#>   id income
#> 1  3     30
#> 2  1     10
#> 
#> studyframe: example | unit: person | current / roster: 2 / 3 
#> Declarations: 0 sampling; 0 weights; 0 assignment.
context(x)$units
#> $observation
#> [1] "person"
#> 
#> $keys
#> $keys[[1]]
#> [1] "id"
#> 
#>