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

Improve error "NAs are not allowed in subscripted assignments" in replacement functions #21

Open
karoliskoncevicius opened this issue Oct 31, 2019 · 5 comments

Comments

@karoliskoncevicius
Copy link
Collaborator

I was working with examples in the help files and stumbled upon this by accident:

x <- c(1, NA, 2)
x %out[]% 2 <- x

Error in x[list] <- values :
  NAs are not allowed in subscripted assignments

This is of course a non-intended usage. But it's a bit unintuitive to receive this message. More so because if x didn't have missing values - it would work:

x <- c(1, 1.5, 2)
x %out[]% 2 <- x

Warning message:
In x[list] <- values :
  number of items to replace is not a multiple of replacement length

x
[1] 1.0 1.5 2.0
@karoliskoncevicius
Copy link
Collaborator Author

@moodymudskipper pinging for opinions.

@moodymudskipper
Copy link
Owner

It's consistent with replace, and to me seems like the right behavior but we could override the error message with a better one.

@karoliskoncevicius
Copy link
Collaborator Author

On a second thought - maybe this also should be left for possible future adjustments. We are close to having a first workable version, so no need to complicate things further until then...

@moodymudskipper
Copy link
Owner

moodymudskipper commented Nov 20, 2019

The translation of the first error is something like this :

The ouput of x %out[]% interval contains undetermined elements (shown as NA values), so in turn the number of the elements to replace is unknown. However you tried x %out[]% interval <- value with a value of length superior to 1 that cannot be assigned or recycled unambiguously.

Your english is better than mine so maybe you'll have a better wording

@moodymudskipper
Copy link
Owner

It wouldn't be that bad to make this warning fail though... As much as I like consistency with base, I think this is never useful, you can have a script running for 20 min, only to spit when it will crash a collection of these warnings, with an intimidating "type warnings() to see the first 50". Maybe better cut it at the source.

@moodymudskipper moodymudskipper changed the title Unintuitive error message in a particular scenario Improve error "NAs are not allowed in subscripted assignments" in replacement functions Nov 25, 2019
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

No branches or pull requests

2 participants