Small inconsistency with empty names in backports of `...names()`
Closed this issue · 5 comments
Dear developers, I was working on a bug in one of my packages and I noticed a small inconsistency in the ...names()
function implemented in backports
vs the function included in R v4.2.1.
For example:
test1 <- function(...) {
...names()
}
test1("ABC")
#> [1] NA
while
bp_...names = getFromNamespace("...names", "backports")
test2 <- function(...) {
bp_...names()
}
test2("ABC")
#> NULL
Created on 2022-02-06 by the reprex package (v2.0.1)
Just a small update: I noticed that the official documentation of ...names()
says that the function returns the names
of the arguments passed down from a calling function using ...
and the official documentation of names()
says the following:
Value
For names, NULL or a character vector of the same length as x. (NULL is given if the object has no names, including for objects of types which cannot have names.
So maybe that's a small inconsistency in the official implementation of ...names()
?
Another discrepancy:
test1 <- function(...) {
...names()
}
test1(a = "b", )
#> [1] "a" NA
bp_...names = getFromNamespace("...names", "backports")
test2 <- function(...) {
bp_...names()
}
test2(a = "b", )
#> [1] "a" ""
Created on 2022-02-10 by the reprex package (v2.0.1)
Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 4.1.2 (2021-11-01)
#> os Windows 10 x64 (build 19042)
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_United Kingdom.1252
#> ctype English_United Kingdom.1252
#> tz Europe/Berlin
#> date 2022-02-10
#> pandoc 2.16.2 @ C:/PROGRA~1/Pandoc/ (via rmarkdown)
#>
#> - Packages -------------------------------------------------------------------
#> package * version date (UTC) lib source
#> backports 1.4.1 2021-12-13 [1] CRAN (R 4.1.2)
#> cli 3.1.1 2022-01-20 [1] CRAN (R 4.1.2)
#> crayon 1.4.2 2021-10-29 [1] CRAN (R 4.1.1)
#> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.2)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.1)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.1)
#> fansi 1.0.2 2022-01-14 [1] CRAN (R 4.1.2)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.1)
#> fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.2)
#> glue 1.6.1 2022-01-22 [1] CRAN (R 4.1.2)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.1.1)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1)
#> knitr 1.37 2021-12-16 [1] CRAN (R 4.1.2)
#> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.1)
#> magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.1.2)
#> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.1.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.1)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.1)
#> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.1.1)
#> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.1.1)
#> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.1.1)
#> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.1.1)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.1)
#> rlang 1.0.1 2022-02-03 [1] CRAN (R 4.1.2)
#> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.1)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.1)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.2)
#> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.1)
#> styler 1.6.2 2021-09-23 [1] CRAN (R 4.1.1)
#> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.2)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.1)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.1)
#> withr 2.4.3 2021-11-30 [1] CRAN (R 4.1.2)
#> xfun 0.29 2021-12-14 [1] CRAN (R 4.1.2)
#> yaml 2.2.2 2022-01-25 [1] CRAN (R 4.1.2)
#>
#> [1] C:/Users/andre/Documents/R/win-library/4.1
#> [2] C:/Program Files/R/R-4.1.2/library
#>
#> ------------------------------------------------------------------------------
Sorry for all these messages.
NB base R's alist()
behaves more in line with backports.
names(alist(a = "b", ))
#> [1] "a" ""
I cannot reproduce the behavior of R's ...names() function on my local machine. I've added your example to the unit tests in d6ca958, they seem to work fine. I also double-checked, the implementation in base did not change AFAICT. Can you try again in a fresh session with only backports loaded? Maybe some other package is overloading ...names()
?
Hi @mllg and thanks for your message. I'm not 100% sure why, but I think that the bug exists only when I compare backports
with R 4.1.2
, whereas the problem was fixed in R 4.1.3
(maybe here: https://bugs.r-project.org/show_bug.cgi?id=18247). I successfully replicated the problem in my fork of this package: agila5#2. I solved my original problem in a different way, but I still wanted to report this slightly problematic interaction.