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

Arguments to the unlist function get removed #1262

Closed
bart1 opened this issue May 26, 2020 · 3 comments
Closed

Arguments to the unlist function get removed #1262

bart1 opened this issue May 26, 2020 · 3 comments

Comments

@bart1
Copy link

bart1 commented May 26, 2020

I'm not sure if this classifies as a bug or not I just noticed that the transformation of targets removes argument from code. The example below shows that both recursive=F and use.names=F get removed in the combine target. If i do not transform the plan this is not an issue. Is there a way avoid these changes in the code. Maybe the transform could ignore formal arguments of the unlist function?

require(drake)
#> Loading required package: drake
drake_plan(a=target(lapply(2:b, sqrt), transform = map(b=!!(4:6))),
           h=target({
             o<-list(a)
             unlist(o, use.names =  F)
           }, transform = combine(a)))
#> # A tibble: 4 x 2
#>   target command                                          
#>   <chr>  <expr>                                           
#> 1 a_4L   lapply(2:4L, sqrt)                               
#> 2 a_5L   lapply(2:5L, sqrt)                               
#> 3 a_6L   lapply(2:6L, sqrt)                               
#> 4 h      {     o <- list(a_4L, a_5L, a_6L)     unlist(o) }
drake_plan(a=target(lapply(2:b, sqrt), transform = map(b=!!(4:6))),
              h=target({
                o<-list(a)
                unlist(o, recursive = F)
              }, transform = combine(a)))
#> # A tibble: 4 x 2
#>   target command                                          
#>   <chr>  <expr>                                           
#> 1 a_4L   lapply(2:4L, sqrt)                               
#> 2 a_5L   lapply(2:5L, sqrt)                               
#> 3 a_6L   lapply(2:6L, sqrt)                               
#> 4 h      {     o <- list(a_4L, a_5L, a_6L)     unlist(o) }
drake_plan(a=target(lapply(2:b, sqrt), transform = map(b=!!(4:6))),
           h=target({
             o<-list(a)
             unlist(o, recursive = F)
           }, transform = combine(a)), transform=F)
#> # A tibble: 2 x 3
#>   target command                                           transform       
#>   <chr>  <expr>                                            <expr>          
#> 1 a      lapply(2:b, sqrt)                                 map(b = !!(4:6))
#> 2 h      {     o <- list(a)     unlist(o, recursive = F) } combine(a)

Created on 2020-05-26 by the reprex package (v0.3.0)

@bart1
Copy link
Author

bart1 commented May 26, 2020

A quick work around is to define a small function:

ff<- function(...) unlist(recursive = F,...)
drake_plan(a=target(lapply(2:b, sqrt), transform = map(b=!!(4:6))),
           h=target({
             o<-list(a)
             ff(o)
           }, transform = combine(a)), transform=T)

Alternatively the lists can be concatenated:

p<-drake_plan(a=target(lapply(2:b, sqrt), transform = map(b=!!(4:6))),
              h=target({
                o<-c(a)
              }, transform = combine(a)))

Maybe these are simple enough not really to make an issue out if it?

@wlandau
Copy link
Member

wlandau commented May 26, 2020

This is a strange edge case. It happens because the splicing code calls do.call("c", args, quote = TRUE) on the arguments to your command, and the c() function has formal arguments use.names and recursive.

args <- do.call("c", args, quote = TRUE)

I see no other way to fix this other than to add back those arguments manually after do.call(). should be fixed now.

@bart1
Copy link
Author

bart1 commented May 26, 2020

Thank you for the quick fix!

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