-
Notifications
You must be signed in to change notification settings - Fork 66
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
vectors with same attributes incompatible #1730
Comments
We have a same-type fallback that kicks in when all attributes are the same, but in this case I see that this attribute contains a function with a varying environment:
You can fix this by implementing identity self-to-self ptype2 and cast methods. Implementing these methods is a good idea in general because it's also be a bit faster than the fallback paths. See https://vctrs.r-lib.org/reference/howto-faq-coercion.html for more information. |
I appreciate this comment. I am trying to follow those FAQ to modify the formattable package, but I am not understanding. I modified my local copy of the formattable package to have #' @importFrom vctrs vec_ptype2 vec_cast
NULL
#' @export
vec_ptype2.num_currency.num_currency <- function(x, y, ...) {
x
}
#' @export
vec_cast.num_currency.num_currency <- function(x, to, ...) {
x
} But, after I > curr1 <- num_currency(1:5)
> curr2 <- num_currency(6:10)
>
> vec_ptype2(curr1,curr2)
Error:
! Can't combine `curr1` <formattable> and `curr2` <formattable>.
✖ Some attributes are incompatible.
ℹ The author of the class should implement vctrs methods.
ℹ See <https://vctrs.r-lib.org/reference/faq-error-incompatible-attributes.html>.
Run `rlang::last_error()` to see where the error occurred. Likely a continuation of my lack of understanding, but I also tried the following (it also did not work): #' @importFrom vctrs vec_ptype2 vec_cast
NULL
#' @export
vec_ptype2.formattable.formattable <- function(x, y, ...) {
x
}
#' @export
vec_cast.formattable.formattable <- function(x, to, ...) {
x
} interestingly enough, I can build vectors vctrs::vec_c(currency(1:3),currency(2:4))
# [1] $1.00 $2.00 $3.00 $2.00 $3.00 $4.00 |
Did you redocument before loading-all? |
Thank you for helping me through this. It works now. I can run over the conceptual implications with folks on the formattable package. |
I don't understand why I get an error from
vctrs::vec_ptype2()
when comparing the type of two vectors with the same formatting. When they are created in the same way, how can they not be compatible.Inspired from formattable issue
The text was updated successfully, but these errors were encountered: