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

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).


Yes, $ will do partial matching. Check the R document of the $ function by typing in the console

?`$`

In the help document it says:

Both [[ and $ select a single element of the list. The main difference is that $ does not allow computed indices, whereas [[ does. x$name is equivalent to x[["name", exact = FALSE]]. Also, the partial matching behavior of [[ can be controlled using the exact argument.

According to Hadley Wickham's book "Advanced R", you can turn off the partial matching of $ by setting the global option warnPartialMatchDollar to TRUE, but it may affect behavior in other code you have loaded, e.g. from a package.

Tags:

R