You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since R 3.4.0 utils::hasName() was added as a convient way of testing the existence of a name i.e. the pattern "name" %in% names(x) or for checking the !is.null(x$abc) pattern without partial matching (taken from the docs):
x<-list(abc=1, def=2)
!is.null(x$abc) # correct!is.null(x$a) # this is the wrong test!
hasName(x, "abc")
hasName(x, "a")
There is also the basically equivalent rlang::has_name() as a common pattern.
The text was updated successfully, but these errors were encountered:
I'm slightly ambivalent on whether hasName(x, nm) is better than nm %in% names(x), seem similar. Happy to host the linter though, it seems reasonable enough as a case of "use the specific function from base".
Since %in% is just match() under the hood, we can also detect the direct match() equivalent, which is much worse:
Since R 3.4.0
utils::hasName()
was added as a convient way of testing the existence of a name i.e. the pattern"name" %in% names(x)
or for checking the!is.null(x$abc)
pattern without partial matching (taken from the docs):There is also the basically equivalent rlang::has_name() as a common pattern.
The text was updated successfully, but these errors were encountered: