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
The documentation for modify says that the .x parameter is "A list or atomic vector." and the "Value" section says that the functions will return "An object the same class as .x" However for atomic vectors, it seems to return a list, and not a vector of the same class as .x.
x <- c("a","b","c","d","e")
y <- c(1, 2, 3, 4, 5)
z <- c(T, F, T, F, T)
class(modify(x,function(x) "k"))
# [1] "list" ## not class(x)
class(modify(y,function(x) 10))
# [1] "list" ## not class(y)
class(modify_if(x, z, function(x) "k"))
# [1] "list" ## not class(x)
class(modify_if(y, z, function(x) x+10))
# [1] "list" ## not class(y)
The help page also says that modify() is basically the same as x[] <- map(x, .f) and ifs that's the case i'd expect map() to return a list, But even on the ?map help page it calls out: "See the modify() family for versions that return an object of the same type as the input."
Tested with purrr_0.2.4 and R version 3.4.1 (2017-06-30)
The text was updated successfully, but these errors were encountered:
MrFlick
changed the title
modify not maintaining class for atomic vectors
modify() not maintaining class for atomic vectors
Nov 22, 2017
Question: has this issue been resolved? I stubbed my toe on it today using the CRAN version purrr_0.2.5 and the list conversion is still happening. I reverted to the dev version, which appears to be purrr_0.2.4.9000, and it's fixed there. My confusion arises from my assumption that 0.2.5 comes after0.2.4.9000 in the version schema. Am I wrong? Or worse, was it fixed, then reverted? Or should the development version actually read 0.2.5.9000. In which case I humbly withdraw my question ;)
The documentation for
modify
says that the.x
parameter is "A list or atomic vector." and the "Value" section says that the functions will return "An object the same class as.x
" However for atomic vectors, it seems to return a list, and not a vector of the same class as.x
.The help page also says that
modify()
is basically the same asx[] <- map(x, .f)
and ifs that's the case i'd expectmap()
to return a list, But even on the?map
help page it calls out: "See themodify()
family for versions that return an object of the same type as the input."Tested with
purrr_0.2.4
andR version 3.4.1 (2017-06-30)
The text was updated successfully, but these errors were encountered: