list members can be accessed with partial name? Is this a feature?

前端 未结 2 455
轻奢々
轻奢々 2021-01-04 23:53

Consider this R code

> l = list(key = 1)
> l$k
[1] 1
> l$ke
[1] 1
> l[[\'k\']]
NULL
> names(l)
[1] \"key\"

Does this mean th

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 00:31

    It's a feature that is meant to help in interactive mode. You can tighten it locally, see help(options) which has

     ‘warnPartialMatchArgs’: logical.  If true, warns if partial
          matching is used in argument matching.
    
     ‘warnPartialMatchAttr’: logical.  If true, warns if partial
          matching is used in extracting attributes via ‘attr’.
    
     ‘warnPartialMatchDollar’: logical.  If true, warns if partial
          matching is used for extraction by ‘$’.
    

    Example:

    R> l <- list(key = 1)
    R> l$k
    [1] 1
    R> options("warnPartialMatchDollar"=TRUE)
    R> l$k
    [1] 1
    Warning message:
    In l$k : partial match of 'k' to 'key'
    R> 
    

    and you can further promote warnings to errors if you so choose (and that option is described on the same page).

提交回复
热议问题