-
Notifications
You must be signed in to change notification settings - Fork 37
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
Call vec_restore() on original objects, call vec_proxy() before operating #316
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restoration is towards the original input, not the proxy.
- Take the proxy
- Operate on proxy
- Restore result to input
@@ -198,5 +198,5 @@ vec_cast.character.pillar_char <- function(x, to, ...) { | |||
} | |||
#' @export | |||
vec_cast.pillar_char.character <- function(x, to, ...) { | |||
vec_restore(x, to) | |||
vec_restore(vec_proxy(x), to) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm actually in this case this doesn't make much of a difference since cast methods are not inherited. So you're guaranteed to get a bare character. Sorry for misleading you here.
@@ -185,7 +185,7 @@ vec_arith.pillar_num <- function(op, x, y, ...) { | |||
vec_arith.pillar_num.default <- function(op, x, y, ...) { | |||
"!!!!DEBUG vec_arith.pillar_num.default(`v(op)`)" | |||
stopifnot(is.numeric(x), is.numeric(y)) | |||
out <- vec_arith_base(op, x, y) | |||
out <- vec_arith_base(op, vec_proxy(x), vec_proxy(y)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is quite right, but I don't have any better advice for generic vec_arith()
at the moment. Since you check for is.numeric()
above, it feels a bit unnecessary to take the proxy because you're restricting the inputs to have numeric storage.
Also conceptually there is no general guarantee that vec_proxy()
is the adequate numeric storage for arithmetic operations. For instance the proxy might be a data frame (record type) and the numeric storage might be in a column of that data frame. For the moment though, we don't have anything better in vctrs.
.