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
replace ops are built around x <- replace(x, cond, value) with specific cases for
factors
when the condition is never met.
I'm questioning both special cases.
First case was to counter this :
x<-factor(letters[1:3])
x[x=="b"] <-"Z"#> Warning in `[<-.factor`(`*tmp*`, x == "b", value = "Z"): niveau de facteur#> incorrect, NAs générésx#> [1] a <NA> c #> Levels: a b c
so x == "b" <- "Z" would replace the levels smoothly.
I think it might have been a bad idea as we could simply do : levels(x) == "b" <- "Z" in that case with more consistency and less ambiguity in some corner cases.
Special case for when the condition was never met was designed so the following wouldn't alter x :
x <- 1:3
x < 0 <- "a"
but now I think it's good that x[x <0] <- "a" coerces to character even if the condition is never met, because of type stability. and our assignment functions would be more intuitive if they were all really simple shortcuts for cond(x) <- value equivalent to x[cond(x)] <- value.
@KKPMW do you see a problem with simplifying those ?
The text was updated successfully, but these errors were encountered:
replace ops are built around
x <- replace(x, cond, value)
with specific cases forI'm questioning both special cases.
First case was to counter this :
so
x == "b" <- "Z"
would replace the levels smoothly.I think it might have been a bad idea as we could simply do :
levels(x) == "b" <- "Z"
in that case with more consistency and less ambiguity in some corner cases.Special case for when the condition was never met was designed so the following wouldn't alter x :
but now I think it's good that
x[x <0] <- "a"
coerces to character even if the condition is never met, because of type stability. and our assignment functions would be more intuitive if they were all really simple shortcuts forcond(x) <- value
equivalent tox[cond(x)] <- value
.@KKPMW do you see a problem with simplifying those ?
The text was updated successfully, but these errors were encountered: