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

dots_list() inconsistency with splicing and unnamed arguments in homonym check. #1740

Open
jpryby opened this issue Aug 14, 2024 · 0 comments

Comments

@jpryby
Copy link

jpryby commented Aug 14, 2024

When using the .named=TRUE argument, the homonym check will fail to catch issues if the same set of arguments are passed as a spliced list that would fail if passed directly, leading to users having to add a secondary check if homonyms are not allowed. This seems to occur when the argument being passed is a variable.

reprex below.

library(rlang)
packageVersion("rlang")
#> [1] '1.1.4'

R.version$version.string
#> [1] "R version 4.4.1 (2024-06-14 ucrt)"


df <- data.frame()
named_list <- list(a=df,b=df)
unnamed_list <- unname(named_list)
basic_list <- list(1,2,3)

identical(
    dots_list(!!!named_list), 
    dots_list(a=df,b=df)
)
#> [1] TRUE

identical(
    dots_list(!!!unnamed_list), 
    dots_list(df,df)
)
#> [1] TRUE

identical(
    dots_list(!!!unnamed_list, .named=TRUE), 
    dots_list(df,df, .named=TRUE)
)
#> [1] FALSE

dots_list(!!!unnamed_list, .named=TRUE, .homonyms= "error")
#> $`<df[,0]>`
#> data frame with 0 columns and 0 rows
#> 
#> $`<df[,0]>`
#> data frame with 0 columns and 0 rows

try(dots_list(df,df, .named=TRUE, .homonyms= "error"))
#> Error : Arguments in `...` must have unique names.
#> ✖ Multiple arguments named `df` at positions 1 and 2.

dots_list(!!!basic_list, .named=TRUE, .homonyms= "error")
#> $`1`
#> [1] 1
#> 
#> $`2`
#> [1] 2
#> 
#> $`3`
#> [1] 3

try(dots_list(1,2,3, .named=TRUE, .homonyms= "error"))
#> $`1`
#> [1] 1
#> 
#> $`2`
#> [1] 2
#> 
#> $`3`
#> [1] 3

Created on 2024-08-14 with reprex v2.1.0

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

No branches or pull requests

1 participant