Can I access the R list using a partial name? Is this a feature?

Consider this code R

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

Does this mean that you can access the list item with $and its partial name? I could not believe my eyes when I discovered this after an unsuccessful hunt for mistakes.

Is this a feature of the R list? Is there a name for this? Is it possible to disable it? This causes obvious problems when you use it as a Python recorder.

+4
source share
2 answers

This is a feature that is designed to help online. 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> 

, ( ).

+5

, $ . R $,

?`$`

:

[[ $ . , $ , [[ . x$name x[["name", exact = FALSE]]. , [[ .

"Advanced R", $, warnPartialMatchDollar TRUE, , . .

+1

Source: https://habr.com/ru/post/1692928/


All Articles