Skip to contents

This function sets new edibble variables of class edbl_unit. More specifically, this means that new nodes are added to the edbl_graph.

Usage

set_units(
  .edibble = design(),
  ...,
  .name_repair = c("check_unique", "unique", "universal", "minimal"),
  .record = TRUE
)

Arguments

.edibble

An edibble design (edbl_design), an edibble data frame (edbl_table) or an object that contains the edibble data frame in the attribute design.

...

Either a name-value pair or a series of the names.

.name_repair

Same as the argument in tibble::tibble().

.record

A logical value. This indicates whether to record this code step. The default is TRUE. It should remain TRUE unless this function is used as a wrapper in other code.

Value

An edibble design.

Definition of unit

A unit, much like factor, is an over-used word but due to lack of a better word, edibble uses the word "unit" to refer to any entity, physical or otherwise, that pertain to the experiment. This function doen't explicitly distinguish between experimental or observational units, nor is a unit limited to these type of units. A unit in edibble can be a blocking factor or even a discrete time unit.

Limitations

Currently a unit should only have a discrete set of levels and you need to know the number of levels prior to setting the units.

See also

Other user-facing functions: allot_trts(), allot_units(), design(), expect_rcrds(), export_design(), serve_table(), set_rcrds(), set_trts()

Examples

# 30 rats
design() %>%
  set_units(rat = 30) %>%
  serve_table()
#> # An edibble: 30 x 1
#>        rat
#>    <U(30)>
#>      <chr>
#>  1   rat01
#>  2   rat02
#>  3   rat03
#>  4   rat04
#>  5   rat05
#>  6   rat06
#>  7   rat07
#>  8   rat08
#>  9   rat09
#> 10   rat10
#> # ℹ 20 more rows

# 4 girls named "Anna", "Betty", "Carol", "Diana"
design() %>%
  set_units(girl = c("Anna", "Betty", "Carol", "Diana")) %>%
  serve_table()
#> # An edibble: 4 x 1
#>     girl
#>   <U(4)>
#>    <chr>
#> 1   Anna
#> 2  Betty
#> 3  Carol
#> 4  Diana

# 3 companies, with 10 boxes each
design() %>%
  set_units(company = c("A", "B", "C"),
                box = nested_in(company, 10))
#> An edibble design
#> └─company (3 levels)
#>   └─box (30 levels)

# 2 classes, one with 10 students, the other with 20 students
design() %>%
  set_units(class = 2,
            student = nested_in(class,
                                1 ~ 10,
                                2 ~ 20))
#> An edibble design
#> └─class (2 levels)
#>   └─student (30 levels)

# 4 countries with 10 people from Australia & New Zealand and 20 from the rest
design() %>%
  set_units(country = c("AU", "NZ", "USA", "JPN"),
            person = nested_in(country,
                               c("AU", "NZ") ~ 10,
                                           . ~ 20)) %>%
  serve_table()
#> # An edibble: 60 x 2
#>    country   person
#>     <U(4)>  <U(60)>
#>      <chr>    <chr>
#>  1      AU person01
#>  2      AU person02
#>  3      AU person03
#>  4      AU person04
#>  5      AU person05
#>  6      AU person06
#>  7      AU person07
#>  8      AU person08
#>  9      AU person09
#> 10      AU person10
#> # ℹ 50 more rows