Skip to contents

Accessors for the parts of an instrument, a codebook, or a report. They replace reaching into the object with $, which ties user code to the internal layout.

Value

A list for sf_meta() and sf_plan() on an instrument, an sf_component_list for the component accessors on an instrument, and a data frame for any of them on a codebook. See the table above.

Details

What each one gives back depends on what it is asked. Given an instrument, the component accessors return the component objects as an sf_component_list, which prints as a list and is subset with [ and [[. Given a codebook, the same verbs return the table the codebook already holds, a plain data frame with one row per item, scale, choice set, model or plan block.

AccessorOn an sframeOn an sframe_codebook
sf_meta()list of metadatalist of metadata
sf_items()sf_component_list of itemsdata frame of items
sf_scales()sf_component_list of scalesdata frame of scales
sf_choice_sets()sf_component_list of choice setsdata frame of choice sets
sf_branches()sf_component_list of branching rulesnot available
sf_checks()sf_component_list of checksnot available
sf_models()sf_component_list of modelsdata frame of models
sf_plan()list of plan blocksdata frame of plan blocks

as.data.frame() on an instrument gives its items as a table, which is one part of it, and a component list has no coercion of its own. For every table an instrument can produce, use codebook_report().

Examples

cs    <- sf_choices("ag5", 1:5,
           c("Strongly disagree", "Disagree", "Neutral",
             "Agree", "Strongly agree"))
item  <- sf_item("sat_1", "The service met my expectations.",
                 type = "likert", choice_set = "ag5", scale_id = "sat")
scale <- sf_scale("sat", "Satisfaction", items = "sat_1")
instr <- sf_instrument("Demo Survey", components = list(cs, item, scale))

sf_meta(instr)$title
#> [1] "Demo Survey"
sf_items(instr)
#> <item list: 1>
#>  <sf_item: sat_1 | type: likert>
sf_scales(instr)[["sat"]]
#> <sf_scale: sat | 1 item(s)>
#>   Label: Satisfaction
#>   Items: sat_1
#>   Scoring: mean
as.data.frame(instr)
#>      id                            label   type choice_set scale_id reverse
#> 1 sat_1 The service met my expectations. likert        ag5      sat   FALSE
#>   required
#> 1    FALSE