Skip to content
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

More thoughts on print method #95

Closed
hadley opened this issue Jun 15, 2016 · 7 comments
Closed

More thoughts on print method #95

hadley opened this issue Jun 15, 2016 · 7 comments

Comments

@hadley
Copy link
Member

hadley commented Jun 15, 2016

While I like the <> in the column descs, I don't like it so much in the overall object description - I think it's a bit distracting.

So how about instead of:

<tibble [32 x 11]>
     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
*  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1   21.0     6 160.0   110  3.90 2.620 16.46     0     1     4     4
2   21.0     6 160.0   110  3.90 2.875 17.02     0     1     4     4
3   22.8     4 108.0    93  3.85 2.320 18.61     1     1     4     1

We have something like this:

# A tibble with 32 rows and 11 columns
     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
*  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1   21.0     6 160.0   110  3.90 2.620 16.46     0     1     4     4
2   21.0     6 160.0   110  3.90 2.875 17.02     0     1     4     4
3   22.8     4 108.0    93  3.85 2.320 18.61     1     1     4     1

Where "A tibble with ..." is generated by a new obj_desc() generic which would return a character vector giving a (potentially) multiple line textual description. print.tbl_df would add the # (and enough spaces to make it line up with the row numbers) and the new lines.

@hadley hadley closed this as completed Jun 15, 2016
@hadley hadley reopened this Jun 15, 2016
@krlmlr
Copy link
Member

krlmlr commented Jun 16, 2016

I actually liked the # A 32 x 11 tibble variant -- did you mean to remove that comment?

@hadley
Copy link
Member Author

hadley commented Jun 16, 2016

Hmmm, I thought it looked ok, but maybe it seems ok now. Here it is again a long with another variant:

# A 32 x 11 tibble
     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
*  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1   21.0     6 160.0   110  3.90 2.620 16.46     0     1     4     4
2   21.0     6 160.0   110  3.90 2.875 17.02     0     1     4     4
3   22.8     4 108.0    93  3.85 2.320 18.61     1     1     4     1
# A tibble: 32 x 11
     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
*  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1   21.0     6 160.0   110  3.90 2.620 16.46     0     1     4     4
2   21.0     6 160.0   110  3.90 2.875 17.02     0     1     4     4
3   22.8     4 108.0    93  3.85 2.320 18.61     1     1     4     1

@dracodoc
Copy link

How about this:
Row description is close to last row, column description is close to columns. Not printed rows or columns are marked with ...

                                          [11 in 11 columns printed]
     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb 
*  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 
1   21.0     6 160.0   110  3.90 2.620 16.46     0     1     4     4
2   21.0     6 160.0   110  3.90 2.875 17.02     0     1     4     4
3   22.8     4 108.0    93  3.85 2.320 18.61     1     1     4     1
[3 in 3 rows printed]
                                         [ 11 in 11 columns printed]
     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb 
*  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 
1   21.0     6 160.0   110  3.90 2.620 16.46     0     1     4     4
2   21.0     6 160.0   110  3.90 2.875 17.02     0     1     4     4
3   22.8     4 108.0    93  3.85 2.320 18.61     1     1     4     1
...
[3 in 32 rows printed]
                               [9 in 11 columns printed] ..
     mpg   cyl  disp    hp  drat    wt  qsec    vs    am ..
*  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> ..
1   21.0     6 160.0   110  3.90 2.620 16.46     0     1 ..
2   21.0     6 160.0   110  3.90 2.875 17.02     0     1 ..
3   22.8     4 108.0    93  3.85 2.320 18.61     1     1 ..
...
[3 in 32 rows printed]

There could also be an option(global option?) to show names of columns that not printed.

@krlmlr krlmlr closed this as completed in 53b1a6a Jun 16, 2016
krlmlr pushed a commit that referenced this issue Jun 16, 2016
- Change formatting of summary line: Begins with hash `#` and contains more text (#95).
- Correctly print list of lists (#97).
@krlmlr
Copy link
Member

krlmlr commented Jun 16, 2016

Just merged an implementation, please comment/reopen/open a new issue in case of any problems.

@krlmlr
Copy link
Member

krlmlr commented Jun 18, 2016

@dracodoc: Columns that would make the output too wide are already printed, see the n_extra argument. I don't really like splitting number of rows and columns like in your example, in particular because other information (think SQL sources or grouped data frames) also needs to be printed. Nevertheless I appreciate your input.

@dracodoc
Copy link

No problem, I just felt it's natural to put row number after the last row. Of course you need to consider all cases and get a balance.

krlmlr pushed a commit that referenced this issue Jul 4, 2016
Follow-up release.

- `tibble()` is no longer an alias for `frame_data()` (#82).
- Remove `tbl_df()` (#57).
- `$` returns `NULL` if column not found, without partial matching. A warning is given (#109).
- `[[` returns `NULL` if column not found (#109).

- Reworked output: More concise summary (begins with hash `#` and contains more text (#95)), removed empty line, showing number of hidden rows and columns (#51). The trailing metadata also begins with hash `#` (#101). Presence of row names is indicated by a star in printed output (#72).
- Format `NA` values in character columns as `<NA>`, like `print.data.frame()` does (#69).
- The number of printed extra cols is now an option (#68, @lionel-).
- Computation of column width properly handles wide (e.g., Chinese) characters, tests still fail on Windows (#100).
- `glimpse()` shows nesting structure for lists and uses angle brackets for type (#98).
- Tibbles with `POSIXlt` columns can be printed now, the text `<POSIXlt>` is shown as placeholder to encourage usage of `POSIXct` (#86).
- `type_sum()` shows only topmost class for S3 objects.

- Strict checking of integer and logical column indexes. For integers, passing a non-integer index or an out-of-bounds index raises an error. For logicals, only vectors of length 1 or `ncol` are supported. Passing a matrix or an array now raises an error in any case (#83).
- Warn if setting non-`NULL` row names (#75).
- Consistently surround variable names with single quotes in error messages.
- Use "Unknown column 'x'" as error message if column not found, like base R (#94).
- `stop()` and `warning()` are now always called with `call. = FALSE`.

- The `.Dim` attribute is silently stripped from columns that are 1d matrices (#84).
- Converting a tibble without row names to a regular data frame does not add explicit row names.
- `as_tibble.data.frame()` preserves attributes, and uses `as_tibble.list()` to calling overriden methods which may lead to endless recursion.

- New `has_name() (#102).
- Prefer `tibble()` and `as_tibble()` over `data_frame()` and `as_data_frame()` in code and documentation (#82).
- New `is.tibble()` and `is_tibble()` (#79).
- New `enframe()` that converts vectors to two-column tibbles (#31, #74).
- `obj_sum()` and `type_sum()` show `"tibble"` instead of `"tbl_df"` for tibbles (#82).
- `as_tibble.data.frame()` gains `validate` argument (as in `as_tibble.list()`), if `TRUE` the input is validated.
- Implement `as_tibble.default()` (#71, tidyverse/dplyr#1752).
- `has_rownames()` supports arguments that are not data frames.

- Two-dimensional indexing with `[[` works (#58, #63).
- Subsetting with empty index (e.g., `x[]`) also removes row names.

- Document behavior of `as_tibble.tbl_df()` for subclasses (#60).
- Document and test that subsetting removes row names.

- Don't rely on `knitr` internals for testing (#78).
- Fix compatibility with `knitr` 1.13 (#76).
- Enhance `knit_print()` tests.
- Provide default implementation for `tbl_sum.tbl_sql()` and `tbl_sum.tbl_grouped_df()` to allow `dplyr` release before a `tibble` release.
- Explicit tests for `format_v()` (#98).
- Test output for `NULL` value of `tbl_sum()`.
- Test subsetting in all variants (#62).
- Add missing test from dplyr.
- Use new `expect_output_file()` from `testthat`.
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants