6

Is there any reason why R is automatically printing backticks on the first element of a list?
Or should I file it as a bug?

Take this MWE. In the console it prints out as:

tmp <- list(a = 'a_val', b = 'b_val')
tmp
#> $`a`
#> [1] "a_val"
#> 
#> $b
#> [1] "b_val"

names(tmp)
#> [1] "a" "b"

This is source of problems when using quoted strings as names.
I know it is not the best practice as one should avoid duplicate names, yet it is inconsistent:

tmp2 <- list(a = 'a_val', b = 'b_val', `a` = 'a_val2', `+` = 'plus_val')
tmp2
#> $`a`
#> [1] "a_val"
#> 
#> $b
#> [1] "b_val"
#> 
#> $a
#> [1] "a_val2"
#> 
#> $`+`
#> [1] "plus_val"

names(tmp2)
#> [1] "a" "b" "a" "+"

Session info

devtools::session_info()

#> Session info ------------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.0 (2018-04-23)
#>  system   x86_64, mingw32             
#>  ui       Rgui                        
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  tz       Europe/Berlin               
#>  date     2018-05-17                  
#> 
#> Packages ----------------------------------------------------------------------
#>  package    * version date       source        
#>  base       * 3.5.0   2018-04-23 local         
#>  compiler     3.5.0   2018-04-23 local         
#>  datasets   * 3.5.0   2018-04-23 local         
#>  devtools     1.13.5  2018-02-18 CRAN (R 3.5.0)
#>  digest       0.6.15  2018-01-28 CRAN (R 3.5.0)
#>  graphics   * 3.5.0   2018-04-23 local         
#>  grDevices  * 3.5.0   2018-04-23 local         
#>  memoise      1.1.0   2017-04-21 CRAN (R 3.5.0)
#>  methods    * 3.5.0   2018-04-23 local         
#>  rstudioapi   0.7     2017-09-07 CRAN (R 3.5.0)
#>  stats      * 3.5.0   2018-04-23 local         
#>  utils      * 3.5.0   2018-04-23 local         
#>  withr        2.1.2   2018-03-15 CRAN (R 3.5.0)
Lorenzo G
  • 561
  • 4
  • 8

0 Answers0