-
Notifications
You must be signed in to change notification settings - Fork 38
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
abbreviations for timezones, #25 #53
Conversation
Hi @krlmlr and @hadley, I think this is ready for your input. I have made some tests that make sure that all Olson abbreviations are in fact 14 characters or fewer, and that all Olson abbreviations are unique. These tests pass on Mac, Windows, and Linux. I also had a look at the abbreviations themselves - they seem OK to me, but you may have different opinions :) The function takes only one timezone at a time, so to see them all at once I use (unsurprisingly) purrr::map_chr(OlsonNames(), abbreviate_olson) Earlier in this thread, I have a few questions. Thanks for having a look! |
Thanks. I've uploaded a copy of the list of abbreviations from my system: https://gist.github.com/krlmlr/cc981acfd19931f9d56061848ff2447d I wonder if we always should be using the abbreviation for the first component, even if the long form fits, so that We shouldn't give a warning, but maybe indicate non-uniqueness with a special symbol such as |
The filename seems ok, exporting seems fine as well. (This is a fairly low-level package, users are mostly other packages and may have legitimate uses for this functionality.) |
Thanks! I will remove the warning and see what I can do with I spent some time arguing with myself on the abbreviation-consistency question you raised, when I put the function together. Maybe what I can do is make that an option in the function call, e.g. Perhaps pillar could propose a default, and it could be overriden with an option? |
…d level names are abbreviated consistently. adds tests
I think this may be ready for another look. I changed the abbreviation-function so that its default is to make a consistent abbreviation of the first and second elements, e.g. I have removed the warning. I have made it possible to request a width of as small as 8. A few things to keep in mind as the width gets smaller:
To test uniqueness at runtime would require evaluating all the timezones whenever the function is called - I don't know if this would make this function too "heavy". Could this function be called using Here are the current results (Mac) for using https://gist.github.com/ijlyttle/58152793e0d7854961fdfc86d5cf60b9 |
vectorize abbreviate_olson()
Thanks. I think it's important to have consistent display across all invocations of printing a tibble (for the same width), so I suggest to compute a dictionary for the abbreviations of all I think the abbreviations will be better if one-, two- and three-component time zones are processed separately. We need to do a bit of gymnastics with Would that work? |
I think I get the idea - let me wrestle with the newly-vectorized function so that it will do what you describe. In the short term, I can get us to a non-memoised version. I need to do some reading on memoise, as I have not yet used it. |
@krlmlr - Another question for you: your vectorization uses purrr functions, but pillar does not import purrr. Does this present a difficulty? I have started to see what I can do using only base - I think there may be a way through, but I would sure like to have |
Hi @krlmlr, I am embarrassed to say that I have not used memoise yet, so I am on shaky ground. My idea is to:
Is this a plausible way? It is not evident to me how |
I totally forgot Maybe we should stick to a hard-coded width of 12 (width of date minus width of Your suggested approach looks like the safest way to avoid a build-time dependency on memoise, I keep forgetting about this problem. Would it work to just overwrite |
I think I get the idea here. Let me see what I can do. Crazy question: how should we approach the case where the The simplest thing to do, for now, would be to use the default |
Thanks. Agree to use |
@krlmlr I have everything done - I imagine that the last thing that I did, updating I can poke around to amend the tests, but any guidance you can provide will be very welcome. |
Aside from tests, here's what happens on my computer: library("lubridate")
library("pillar")
now_tz <- with_tz(now(), "America/New_York")
type_sum(now_tz)
library("tibble")
as_tibble(now_tz)
Now that things are "working", I thought I might raise some options because 12 characters seems a little confining.
Thoughts? |
One last question - can you have a look at the implementation of memoize: I could not get this to work in It works for me this way, but I have no idea if this is a good practice or a horrible practice. Thanks! |
Some tests create files with output, and fail the first time they are run if the output changes. They should work the second time, but you may need to rerun all tests a few times until convergence. (testtthat aborts early if there are too many failures.) Can you show the output for the various options you're suggesting? The current memoise implementation installs the function during build time, it's better to do in |
I will fiddle with tests, as well as get things working with Here are the assumed outputs resulting from the options. library("lubridate")
library("pillar")
library("tibble")
now_tz <- with_tz(now(), "America/New_York")
as_tibble(now_tz) As is:
Discarding
Same option, but run with timezone absent: as_tibble(now())
|
Hi @krlmlr, Good news: I think I have Bad news: I am having trouble to get the tests to do what you describe - I keep getting the same errors again and again, no convergence. Error for this test:
|
Hi @krlmlr, I found that the tests were not passing because I had an actual problem in my code; I have taken care of it. The tests run OK now, but now I am having a problem running Edit - having updated to latest github version of
I see this is addressed in r-lib/pkgapi#21. Once that is sorted out, it remains to see if you want to change the styling of the header (above). |
Thanks for your patience. I suspect this should live elsewhere (perhaps in lubridate?), tidyverse/tibble#411 (or a variant thereof) will provide the necessary infrastructure. |
I agree, I will look elsewhere :) |
Thanks again! Let me know when you find a home for this useful functionality. |
This is a first pass to address #25.
Things I still need to sort out:
Questions
abbreviate_olson()
has an argument to specify the maximum width of what is returned. I am confident it will work for any value 14 or greater. It may not work at less than 13. For now, I throw a warning ifwidth < 14
; is this the "right" thing to do?abbreviate_olson()
be exported? - I am doing so just to motivate documentation, but perhaps it does not need to be.I'm sure you will have more suggestions. I will signal when I think it will be worth looking at, but will welcome your feedback in the meantime.