emitanaka / edibble

An R-package that encapsulate elements of experimental design for better planning, management, and workflow
https://edibble.emitanaka.org
Other
215 stars 14 forks source link

Fix input for factors #60

Closed emitanaka closed 1 year ago

emitanaka commented 1 year ago
library(edibble)
design() %>% 
  set_units(pen = fct_attrs(levels = 3)) %>% 
  serve_table()
#> # An edibble: 3 x 1
#>         pen
#>   <unit(3)>
#> 1      pen1
#> 2      pen2
#> 3      pen3

Above is supposed to be

#> # An edibble: 1 x 1
#>         pen
#>   <unit(1)>
#> 1      3

Also

design() %>% set_units(pen = 1:3) %>% serve_table() -> x
unclass(x$pen)
#> [1] "1" "2" "3"
#> attr(,"levels")
#> [1] "1" "2" "3"
#> attr(,"name")
#> [1] "pen"

is supposed to be numeric values!

emitanaka commented 1 year ago

Oh actually first part was supposed to be:

library(edibble)
design() %>% 
  set_units(pen = fct_attrs(levels = lvl_attrs(3))) %>% 
  serve_table()
#> # An edibble: 1 x 1
#>         pen
#>   <unit(1)>
#> 1         3
emitanaka commented 1 year ago

Okay, it's supposed to be like below.

library(edibble)
design() %>% 
  set_units(pen = lvl_attrs(3)) %>% 
  serve_table()
#> # An edibble: 1 x 1
#>         pen
#>   <unit(1)>
#> 1         3

Now I remember why I allowed for the first specification. The first specification still allows for the shorthand expression of the levels whilst specifying the factor metadata. Is this a wise thing to do? I guess it's fair. For strict level specification, one should use lvl_attrs, for strict factor specification, one should use fct_attrs. If you want both to be strict, use both.

emitanaka commented 1 year ago

fixed in the new internals