-
Notifications
You must be signed in to change notification settings - Fork 129
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
Add max string length option #104
Conversation
if set to a number, strings longer than this number will be shortend with `...`. E.g. `options(tibble.print_string_max = 10) will only print up to 10 characters of each string.
Current coverage is 99.83%@@ master #104 diff @@
==========================================
Files 14 14
Lines 590 595 +5
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 589 594 +5
Misses 1 1
Partials 0 0
|
Unfortunately, |
I'm not generally opposed to limiting string length, but I think #89 was about adaptive shortening that is applied as needed if the output is too wide. |
@krlmlr so the algo would be I will do the changes, if that's what you want :-) |
It would help to see an example, see the expect_output() calls in the tests. |
This is an example with the current implementation and
|
Nice. If you could enhance the output tests, so that the "known output" becomes part of this PR? Just add a test to test-trunc-mat.r, the test file will be generated if it's missing. See #100 for problems with "wide" characters in certain scripts. For instance, I'm getting: > sprintf("%.*s...", 4, "合同录入日期")
[1] "合\xe5..." We need a better method to shorten a string to a given "visible" width. @hadley: Should string columns be limited to width 20 by default? |
Shortening by default feels a bit too aggressive to me - I'd prefer to do only if there's not enough space. Ideally a one column df with long string would be truncated to screen width. |
@JanSchulz: Would you like to contribute more to this PR? See #104 (comment). |
@krlmlr I should have time to work on this from wednesday next week... Sorry if that's too late :-/ Regarding the unicode stuff: is So, to recap the requirements:
Algo:
|
Thanks. No hurry. nchar(type = "width") works in RStudio and RGui, at least for the examples shown in #100. It works the same in the R terminal on Windows, but the output is printed unhelpfully as The "shortening to screen width" part looks interesting to me in the context of #100. If everything else fails, you could split the strings to code points and calculate the width for each; I'd generally exclude code points with zero width if the next codepoint doesn't fit:
Otherwise, the requirements look good to me. |
Two more points:
|
regarding windows |
Shelving this for now, I think strings with limited width will be easier with #144. |
hello everyone, thanks for your great work! Just wondering if there are any plans about implementing that? I think its pretty useful. For instance, in
which is really helpful when one prints a |
hello there! any updates on this? I tried |
1 similar comment
hello there! any updates on this? I tried |
Development of better column formatting has moved to https://github.com/hadley/colformat. Would you like to contribute there? Comments to a closed issue are not very effective, because it is easy to ignore them. |
thanks @krlmrl ! i ll have a look at it |
If set to a number, strings longer than this number will be shortend with
...
.E.g. `options(tibble.print_string_max = 10) will only print up to 10 characters
of each string.