Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static branching unnames list columns in .data grid #1323

Closed
4 tasks done
shirdekel opened this issue Sep 22, 2020 · 3 comments
Closed
4 tasks done

Static branching unnames list columns in .data grid #1323

shirdekel opened this issue Sep 22, 2020 · 3 comments

Comments

@shirdekel
Copy link

Prework

  • Read and abide by drake's code of conduct.
  • Search for duplicates among the existing issues, both open and closed.
  • Be considerate of the maintainer's time and make it as easy as possible to troubleshoot any problems you identify. Read here and here to learn about minimal reproducible examples. Format your code according to the tidyverse style guide to make it easier for others to read.
  • If you think your issue has a quick and definite solution, consider posting to Stack Overflow under the drake-r-package tag. (If you anticipate extended follow-up and discussion, you are already in the right place!)

Description

I want to pass named lists to targets through the .data grid, but something seems to unname them.

Reproducible example

library(drake)
library(tibble)

arg <- 
  list(
    list(A = "a"),
    list(B = "b")
  )

# Retains list names

drake_plan(
  x = target(
    arg,
    transform = map(
      arg = !!arg,
      .id = FALSE
    )
  )
)
#> # A tibble: 2 x 2
#>   target command      
#>   <chr>  <expr_lst>   
#> 1 x      list(A = "a")
#> 2 x_2    list(B = "b")

my_grid <- 
  tibble(
    arg = arg
  )

# Removes list names

drake_plan(
  x = target(
    arg,
    transform = map(
      .data = !!my_grid,
      .id = FALSE
    )
  )
)
#> # A tibble: 2 x 2
#>   target command   
#>   <chr>  <expr_lst>
#> 1 x      list("a") 
#> 2 x_2    list("b")

Created on 2020-09-22 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       macOS Mojave 10.14.6        
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_AU.UTF-8                 
#>  ctype    en_AU.UTF-8                 
#>  tz       Australia/Sydney            
#>  date     2020-09-22                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.0)
#>  backports     1.1.9   2020-08-24 [1] CRAN (R 4.0.2)
#>  base64url     1.4     2018-05-14 [1] CRAN (R 4.0.0)
#>  callr         3.4.4   2020-09-07 [1] CRAN (R 4.0.2)
#>  cli           2.0.2   2020-02-28 [1] CRAN (R 4.0.0)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.0)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.0)
#>  devtools      2.3.0   2020-04-10 [1] CRAN (R 4.0.0)
#>  digest        0.6.25  2020-02-23 [1] CRAN (R 4.0.0)
#>  drake       * 7.12.2  2020-06-02 [1] CRAN (R 4.0.0)
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.0)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.0)
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.0)
#>  filelock      1.0.2   2018-10-05 [1] CRAN (R 4.0.0)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.0)
#>  hms           0.5.3   2020-01-08 [1] CRAN (R 4.0.0)
#>  htmltools     0.5.0   2020-06-16 [1] CRAN (R 4.0.0)
#>  igraph        1.2.5   2020-03-19 [1] CRAN (R 4.0.0)
#>  knitr         1.29    2020-06-23 [1] CRAN (R 4.0.2)
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.0)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.0)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 4.0.0)
#>  pillar        1.4.6   2020-07-10 [1] CRAN (R 4.0.1)
#>  pkgbuild      1.1.0   2020-07-13 [1] CRAN (R 4.0.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.0)
#>  pkgload       1.1.0   2020-05-29 [1] CRAN (R 4.0.0)
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.0)
#>  processx      3.4.4   2020-09-03 [1] CRAN (R 4.0.2)
#>  progress      1.2.2   2019-05-16 [1] CRAN (R 4.0.0)
#>  ps            1.3.4   2020-08-11 [1] CRAN (R 4.0.2)
#>  R6            2.4.1   2019-11-12 [1] CRAN (R 4.0.0)
#>  remotes       2.1.1   2020-02-15 [1] CRAN (R 4.0.0)
#>  rlang         0.4.7   2020-07-09 [1] CRAN (R 4.0.1)
#>  rmarkdown     2.3     2020-06-18 [1] CRAN (R 4.0.0)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 4.0.0)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.0)
#>  storr         1.2.1   2018-10-18 [1] CRAN (R 4.0.0)
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.2)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.0)
#>  testthat      2.3.2   2020-03-02 [1] CRAN (R 4.0.0)
#>  tibble      * 3.0.3   2020-07-10 [1] CRAN (R 4.0.1)
#>  txtq          0.2.0   2019-10-15 [1] CRAN (R 4.0.0)
#>  usethis       1.6.1   2020-04-29 [1] CRAN (R 4.0.0)
#>  utf8          1.1.4   2018-05-24 [1] CRAN (R 4.0.0)
#>  vctrs         0.3.4   2020-08-29 [1] CRAN (R 4.0.2)
#>  withr         2.2.0   2020-04-20 [1] CRAN (R 4.0.0)
#>  xfun          0.17    2020-09-09 [1] CRAN (R 4.0.2)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

Desired result

The .data grid retaining list element names.

@wlandau
Copy link
Collaborator

wlandau commented Sep 22, 2020

Names should stick in 9fb42f5. But whether you use the CRAN version or the dev version, it's recommended in this case to use language objects than lists.

library(drake)
library(tibble)

grid <- tibble(
  arg = list(
    quote(list(A = "a")),
    quote(list(B = "b"))
  )
)

drake_plan(
  x = target(
    arg,
    transform = map(
      .data = !!grid,
      .id = FALSE
    )
  )
)
#> # A tibble: 2 x 2
#>   target command      
#>   <chr>  <expr_lst>   
#> 1 x      list(A = "a")
#> 2 x_2    list(B = "b")

Created on 2020-09-22 by the reprex package (v0.3.0)

@shirdekel
Copy link
Author

shirdekel commented Sep 22, 2020

Thanks for the quick fix! Can you explain the benefit of quoting/using language objects?

@wlandau
Copy link
Collaborator

wlandau commented Sep 22, 2020

drake_plan() creates code, and static branching inserts symbols to help automate that code generation. So your first example was really trying to bootstrap back the code that generated the list objects in arg. It’s usually better to begin with code or basic types to avoid having to reconstruct the code that generated the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants