Skip to content

Commit

Permalink
Merge branch 'f-#95-print'. Fixes #95.
Browse files Browse the repository at this point in the history
- Change formatting of summary line: Begins with hash `#` and contains more text (#95).
  • Loading branch information
Kirill Müller committed Jun 16, 2016
2 parents 4678202 + eeafac0 commit 53b1a6a
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 22 deletions.
17 changes: 13 additions & 4 deletions R/type-sum.r
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ obj_sum.POSIXlt <- function(x) {
rep("POSIXlt", length(x))
}

#' @export
obj_sum.tbl_df <- function(x) {
paste0("A tibble: ", dim_desc(x))
}

#' @export
#' @rdname obj_sum
type_sum <- function(x) UseMethod("type_sum")
Expand Down Expand Up @@ -68,13 +73,17 @@ type_sum.default <- function(x) {
}
}

size_sum <- function(x) {
if (!is_vector_s3(x)) return("")

dim_desc <- function(x) {
dim <- dim(x) %||% length(x)
format_dim <- vapply(dim, big_mark, character(1))
format_dim[is.na(dim)] <- "??"
paste0(" [", paste0(format_dim, collapse = " x "), "]" )
paste0(format_dim, collapse = " x ")
}

size_sum <- function(x) {
if (!is_vector_s3(x)) return("")

paste0(" [", dim_desc(x), "]" )
}

#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/utils-format.r
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ format_summary <- function(x) {
}

print_summary <- function(x) {
cat("<", format_summary(x), ">\n", sep = "")
cat("# ", wrap(format_summary(x), width = getOption("width")), "\n", sep = "")
}

print_table <- function(x) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/POSIXlt-8-30.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [12 x 2]>
# A tibble: 12 x 2
x y
<time> <time>
1 2016-01-01 12:34:57 <POSIXlt>
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/all--30.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [3 x 9]>
# A tibble: 3 x 9
a b c d
<dbl> <int> <lgl> <chr>
1 1.0 1 TRUE a
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/all--300.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [3 x 9]>
# A tibble: 3 x 9
a b c d e f g h
<dbl> <int> <lgl> <chr> <fctr> <date> <time> <list>
1 1.0 1 TRUE a a 2015-12-10 2015-12-09 10:51:35 <int [1]>
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/all-1-30-0.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [3 x 9]>
# A tibble: 3 x 9
a b c d
<dbl> <int> <lgl> <chr>
1 1 1 TRUE a
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/all-1-30-2.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [3 x 9]>
# A tibble: 3 x 9
a b c d
<dbl> <int> <lgl> <chr>
1 1 1 TRUE a
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/all-knit-120.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


tibble [3 x 9]
A tibble: 3 x 9

|a |b |c |d |e |f |g |h |i |
|:-----|:-----|:-----|:-----|:------|:----------|:-------------------|:---------|:----------|
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/all-knit-60.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


tibble [3 x 9]
A tibble: 3 x 9

|a |b |c |d |e |f |
|:-----|:-----|:-----|:-----|:------|:----------|
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/iris--70.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [150 x 5]>
# A tibble: 150 x 5
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
<dbl> <dbl> <dbl> <dbl> <fctr>
1 5.1 3.5 1.4 0.2 setosa
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/iris-3-5.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [150 x 5]>
# A tibble: 150 x 5
Sepal.Length
<dbl>
1 5.1
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/iris-5-30.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [150 x 5]>
# A tibble: 150 x 5
Sepal.Length Sepal.Width
<dbl> <dbl>
1 5.1 3.5
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/iris_unk-10-70.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<unknown_rows [?? x 5]>
# A tibble: ?? x 5
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
<dbl> <dbl> <dbl> <dbl> <fctr>
1 5.1 3.5 1.4 0.2 setosa
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/long-5-30.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [10,000 x 1]>
# A tibble: 10,000 x 1
a
<int>
1 1
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/long_unk-5-30.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<unknown_rows [?? x 1]>
# A tibble: ?? x 1
a
<int>
1 1
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/mtcars-8-30.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tibble [32 x 11]>
# A tibble: 32 x 11
mpg cyl disp hp
* <dbl> <dbl> <dbl> <dbl>
1 21.0 6 160.0 110
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/zero-cols_unk-5-30.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<unknown_rows [?? x 0]>
# A tibble: ?? x 0
... with at least 5 rows
total
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/zero_cols-5-30.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<tibble [150 x 0]>
# A tibble: 150 x 0
2 changes: 1 addition & 1 deletion tests/testthat/output/trunc_mat/zero_rows--30.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<tibble [0 x 2]>
# A tibble: 0 x 2
... with 2 variables:
a <chr>, b <lgl>

0 comments on commit 53b1a6a

Please sign in to comment.