Skip to contents

Registers a data frame as the session's default, so the analysis helpers can be called without repeating data every time. Set it once at the top of a script or Quarto document and then omit data (or pass it by pipe).

Usage

use_dataset(data)

Arguments

data

A data frame to use as the default.

Value

data, invisibly (so it can sit in a pipe).

Details

With a default set you can drop data entirely and name the column positionally, the way you would in the tidyverse:

  • calc_percentage(demo_gender) – data taken from the default;

  • podracing_survey %>% calc_percentage(demo_gender) – explicit pipe;

  • calc_percentage(other_survey, demo_gender) – an explicit data frame always wins over the default.

The helpers tell a column from a data frame by looking at the first argument: a data frame is used as the data; anything else (a bare column name) is taken as the first column and the data comes from the default. Helpers that select several columns through ... (e.g. diagnose(), calc_percentage_batch()) work the same way – diagnose(starts_with("ratings_")) needs no data.

The default applies to the analysis helpers that read a raw survey (calc_percentage(), calc_summary(), calc_nps(), diagnose(), crosstab(), ipm_model(), sample_comments(), ...). It does not apply to plot/report helpers that consume an already-summarised table. The setting lives only in the current R session; clear it with clear_dataset().

Examples

use_dataset(podracing_survey)
calc_percentage(demo_gender)   # data taken from the default
#> # A tibble: 3 × 3
#>   demo_gender     n   pct
#>   <chr>       <int> <dbl>
#> 1 Female        399    42
#> 2 Male          525    55
#> 3 Non-binary     27     3
calc_nps(nps_value)
#> # A tibble: 1 × 8
#>       n   nps pct_detractors pct_passives pct_promoters detractors passives
#>   <int> <dbl>          <dbl>        <dbl>         <dbl>      <int>    <int>
#> 1  1000     7             25           43            32        252      426
#> # ℹ 1 more variable: promoters <int>
clear_dataset()