-
Notifications
You must be signed in to change notification settings - Fork 6
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
The max_atomic
arg might generate failing code
#29
Comments
Minimal example and comments inline : time <- as.POSIXct("2022-01-01 00:00:00", "UTC")
constructive::construct(time, max_atomic = 0)
#> as.POSIXct(character(0), tz = character(0))
# Fails because we need a TZ
as.POSIXct(character(0), tz = character(0))
#> Error in if (nzchar(tz)) attr(res, "tzone") <- tz: argument is of length zero
# For a prototype we might expect
as.POSIXct(character(0), tz = "UTC")
#> POSIXct of length 0
identical(as.POSIXct(character(0), tz = "UTC"), vctrs::vec_ptype(time))
#> [1] TRUE
# But that shows the definitions of a prototype and of max_atomic = 0 might be different
# Is this the right max_atomic = 0 version ?
as.POSIXct(character(0)) |>
structure(tzone = character(0))
#> POSIXct of length 0
# or can we say that we can't guarante code to run when max_atomic is set (because we can't)
# and not go through a rabbit hole of exceptions ?
# Also what about objects with a class and no implemented constructor ?
x <- 1
class(x) <- "foo"
constructive::construct(x, max_atomic = 0)
#> numeric(0) |>
#> structure(class = character(0)) In the general case we can't make an exception for class and attributes, because they can be complex (classes themselves can have attributes), so the latter probably has to stay this way. But's important to know that while the standard use enforces equivalence of original and constructed objects, max_atomic trims it in a way that is dependent on the implemented constructors, and thus the output might change as the package gets more constructors. A corollary is that prototypes are defined by arbitrary rules, or at least rules TLDR :
|
If we don't change the code construction, which I currently tend to believe we shouldn't, it might still be good to try by default to run the code, even if check is |
Thanks! Just to recall, from Just for curiosity, is there a theoretical reason for which you would tend to avoid I see the point that {vctrs} seems to have a different opinion on actually "what is a prototype for a POSIXct". What I see is that for {vctrs} a valid time zone should be provided. And, there might actually be a valid "theoretical" reason that underpins this "choice" that I am not aware of, or ignore (btw if there is a theoretical reason there this not even a "choice", but just a fact that follows, right?). So, I cannot see, due to my illiteracy on this topic, what is the degree of "subjectivity" involved in the definition of a "valid prototype". As far as I am concerned,
|
I think it was just using calling dput on zero length elements
Because I think max_atomic's role might be just to show less, not to change the way it's shown. The core feature is not to modify the input but to represent it. I think it's something I oversaw when starting to talk about building prototypes with this package and it's probably a mistake. Also if we did this for POSIXct we'd need to consider exceptions for all constructors to try to build something that works from zero length vectors, and for some it might be impossible anyway.
I think by default So Maybe the two latter functions in the end just check names, class and attributes though.
I don't say We will dissociate completely the concept of |
max_atomic
arg might generate failing code
Let's deal with this in #19 |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
Created on 2022-08-31 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: