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
While pluck works with base functions such as toupper, it doesn't work with functions such as as.character or is.numeric, giving a "must be a character or numeric vector" error.
As far as I can tell, the difference is whether typeof() returns "closure" (always works) or "builtin" (doesn't work).
library(purrr)
x<-list(a="apple", n=3, v=1:5)
# Using a closure works
typeof(toupper)
#> [1] "closure"
pluck(x, "a")
#> [1] "apple"
pluck(x, "a", toupper)
#> [1] "APPLE"# but using a builtin doesn't
typeof(as.character)
#> [1] "builtin"
pluck(x, "n")
#> [1] 3
pluck(x, "n", as.character)
#> Error: Index 2 must be a character or numeric vector
pluck(x, "n", is.double)
#> Error: Index 2 must be a character or numeric vector# It would have worked if we defined it in a functionf.1<-function(x) as.character(x)
pluck(x, "n", f.1)
#> [1] "3"
The text was updated successfully, but these errors were encountered:
Thanks, this is a duplicate of #370. We need to evaluate the accessors in the calling environment so that lexically scoped methods (such as those of the base package which aren't registered) can be found.
While
pluck
works with base functions such astoupper
, it doesn't work with functions such asas.character
oris.numeric
, giving a "must be a character or numeric vector" error.As far as I can tell, the difference is whether
typeof()
returns "closure" (always works) or "builtin" (doesn't work).The text was updated successfully, but these errors were encountered: