Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In is.na<-, value can be any index #947

Closed
danhalligan opened this issue Mar 25, 2020 · 1 comment · Fixed by #954
Closed

In is.na<-, value can be any index #947

danhalligan opened this issue Mar 25, 2020 · 1 comment · Fixed by #954
Assignees

Comments

@danhalligan
Copy link

danhalligan commented Mar 25, 2020

is.na<-.vctrs_vct asserts value argument is a logical.

#' @export

However, in base::R merge.data.frame it may be an index of values to set to NA. See (for example) this section of the merge.data.frame base R function:

        if (all.x) {
            zap <- (lxy + 1L):(lxy + nxx)
            for (i in seq_along(y)) {
                if (is.matrix(y[[1]])) 
                  y[[1]][zap, ] <- NA
                else is.na(y[[i]]) <- zap
            }
        }
@hadley hadley changed the title vctrs is.na assignment erroneously asserts value is logical In is.na<-, value can be any index Mar 25, 2020
@hadley
Copy link
Member

hadley commented Mar 25, 2020

From the is.na docs:

(xx <- c(0:4))
#> [1] 0 1 2 3 4
is.na(xx) <- c(2, 4)
xx
#> [1]  0 NA  2 NA  4

Created on 2020-03-25 by the reprex package (v0.3.0)

Also works with character vectors, so we need to treat value vec_as_location().

y <- c(a = 1, b = 2, c = 3)
is.na(y) <- "b"
y
#>  a  b  c 
#>  1 NA  3

Created on 2020-03-25 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants