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

`export_design` readme example fails #49

Closed mjbroerman closed 2 years ago

mjbroerman commented 2 years ago

Hi Emi,

This is a great package, really helps me consult! One of your examples doesn't work, perhaps due to openxlsx changes.

Thanks! Matt

library(edibble)
library(openxlsx)
set.seed(2020)

des <- design(name = "Effective teaching") %>%
  set_units(class = 4,
            student = nested_in(class, 30)) %>%
  set_trts(
    style = c("flipped", "traditional"),
    exam = c("take-home", "open-book", "closed-book")
  ) %>%
  allot_trts(style ~ class,
             exam ~ student) %>%
  assign_trts("random")

out <- des %>%
  set_rcrds_of(
    student = c("exam_mark",
                "quiz1_mark",
                "quiz2_mark",
                "gender"),
    class = c("room",
              "teacher")
  ) %>%
  expect_rcrds(
    exam_mark <= 100,
    exam_mark >= 0,
    quiz1_mark <= 15L,
    quiz1_mark >= 0L,
    quiz2_mark <= 30L,
    quiz2_mark >= 0L,
    factor(gender, levels = c("female", "male", "non-binary", "unknown"))
  ) %>%
  serve_table()

out
#> # Effective teaching 
#> # An edibble: 120 x 10
#>        class     student       style        exam exam_mark quiz1_mark quiz2_mark
#>    <unit(4)> <unit(120)>    <trt(2)>    <trt(3)>    <rcrd>     <rcrd>     <rcrd>
#>  1    class1   student1  traditional closed-book         o          o          o
#>  2    class1   student2  traditional open-book           o          o          o
#>  3    class1   student3  traditional take-home           o          o          o
#>  4    class1   student4  traditional closed-book         o          o          o
#>  5    class1   student5  traditional take-home           o          o          o
#>  6    class1   student6  traditional take-home           o          o          o
#>  7    class1   student7  traditional open-book           o          o          o
#>  8    class1   student8  traditional open-book           o          o          o
#>  9    class1   student9  traditional closed-book         o          o          o
#> 10    class1   student10 traditional closed-book         o          o          o
#> # … with 110 more rows, and 3 more variables: gender <rcrd>, room <rcrd>,
#> #   teacher <rcrd>

export_design(out, file = "test.xlsx")
#> Error in read.xlsx.Workbook(wb, namedRegion = data_sheet): Region 'Data.student' not found!

Created on 2022-07-05 by the reprex package (v2.0.1)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.2 (2021-11-01) #> os macOS Big Sur 11.4 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/New_York #> date 2022-07-05 #> pandoc 2.17.1.1 @ /Applications/RStudio.app/Contents/MacOS/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> AlgDesign 1.2.1 2022-05-25 [2] CRAN (R 4.1.1) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.1.1) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.1.1) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.1.1) #> edibble * 0.1.0 2022-07-05 [1] Github (emitanaka/edibble@cc40c22) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.0) #> evaluate 0.14 2019-05-28 [2] CRAN (R 4.1.0) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.1.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.0) #> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.1) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.1.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.1.0) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1) #> knitr 1.37 2021-12-16 [2] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.1) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.1.1) #> nestr 0.1.2 2022-02-01 [2] CRAN (R 4.1.1) #> openxlsx * 4.2.5 2021-12-14 [1] CRAN (R 4.1.1) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.1.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.0) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.1.0) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1) #> Rcpp 1.0.8.3 2022-03-17 [2] CRAN (R 4.1.1) #> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.1.1) #> rlang 1.0.3 2022-06-27 [1] CRAN (R 4.1.1) #> rmarkdown 2.11 2021-09-14 [2] CRAN (R 4.1.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.0) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.1) #> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.1.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.1.1) #> tibble 3.1.7 2022-05-03 [2] CRAN (R 4.1.1) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.1.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.0) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.1.1) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.1.1) #> xfun 0.29 2021-12-14 [2] CRAN (R 4.1.1) #> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.1.0) #> zip 2.2.0 2021-05-31 [2] CRAN (R 4.1.0) #> #> [1] /Users/matt/repos/eg-edibble/renv/library/R-4.1/aarch64-apple-darwin20 #> [2] /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
emitanaka commented 2 years ago

Thanks for this and the helpful reprex! I've now fixed this in the latest commit.