Skip to content

Commit

Permalink
use tibble::print.tbl() for printing
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed May 13, 2017
1 parent cf6e0a6 commit 388c001
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 48 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Imports:
glue,
methods,
rlang (>= 0.1.0),
tibble (>= 1.3.0.9003),
R6,
utils
Suggests:
Expand Down
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ S3method(print,semi_join_query)
S3method(print,set_op_query)
S3method(print,sql)
S3method(print,sql_variant)
S3method(print,tbl_lazy)
S3method(print,tbl_sql)
S3method(pull,tbl_sql)
S3method(rename,tbl_lazy)
S3method(rename_,tbl_lazy)
Expand Down Expand Up @@ -205,6 +203,7 @@ S3method(summarise,tbl_lazy)
S3method(summarise_,tbl_lazy)
S3method(tail,tbl_sql)
S3method(tbl,src_dbi)
S3method(tbl_sum,tbl_sql)
S3method(tbl_vars,tbl_lazy)
S3method(ungroup,tbl_lazy)
S3method(union_all,tbl_lazy)
Expand Down
3 changes: 1 addition & 2 deletions R/tbl-lazy.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ group_vars.tbl_lazy <- function(x) {
op_grps(x$ops)
}

#' @export
print.tbl_lazy <- function(x, ...) {
render_lazy <- function(x, ...) {
cat("Source: lazy\n")
cat("Vars : ", commas(op_vars(x$ops)), "\n", sep = "")
cat("Groups: ", commas(op_grps(x$ops)), "\n", sep = "")
Expand Down
23 changes: 8 additions & 15 deletions R/tbl-sql.r
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,16 @@ as.data.frame.tbl_sql <- function(x, row.names = NULL, optional = NULL,
}

#' @export
print.tbl_sql <- function(x, ..., n = NULL, width = NULL) {
cat("Source: ", tbl_desc(x), "\n", sep = "")
cat("Database: ", db_desc(x$src$con), "\n", sep = "")

tbl_sum.tbl_sql <- function(x) {
grps <- op_grps(x$ops)
if (length(grps) > 0) {
cat("Grouped by: ", commas(grps), "\n", sep = "")
}
sort <- op_sort(x$ops)
if (length(sort) > 0) {
cat("Ordered by: ", commas(deparse_all(sort)), "\n", sep = "")
}

cat("\n")

print(trunc_mat(x, n = n, width = width))
invisible(x)
c(
NextMethod(),
paste0("Source: ", tbl_desc(x)),
paste0("Database: ", db_desc(x$src$con)),
if (length(grps) > 0) paste0("Groups: ", commas(grps)),
if (length(sort) > 0) paste0("Ordered by: ", commas(deparse_all(sort)))
)
}

#' @export
Expand Down
11 changes: 5 additions & 6 deletions tests/testthat/output/iris--70.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Source: table<iris-output-test> [?? x 5]
Database: sqlite x.y.z [:memory:]
Grouped by: Species
Ordered by: Sepal.Length

# S3: tbl_dbi
# A tibble: ?? x 5
# Source: table<iris-output-test> [?? x 5]
# Database: sqlite x.y.z [:memory:]
# Groups: Species
# Ordered by: Sepal.Length
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
<dbl> <dbl> <dbl> <dbl> <chr>
1 4.3 3.0 1.1 0.1 setosa
Expand Down
26 changes: 19 additions & 7 deletions tests/testthat/output/iris-3-5.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
Source: table<iris-output-test> [?? x 5]
Database: sqlite x.y.z [:memory:]
Grouped by: Species
Ordered by: Sepal.Length

# S3:
# tbl_dbi
# A
# tibble:
# ??
# x
# 5
# Source:
# table<iris-output-test>
# [??
# x
# 5]
# Database:
# sqlite
# x.y.z
# [:memory:]
# Groups:
# Species
# Ordered
# by:
# Sepal.Length
Sepal.Length
<dbl>
1 4.3
Expand Down
14 changes: 8 additions & 6 deletions tests/testthat/output/iris-5-30.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Source: table<iris-output-test> [?? x 5]
Database: sqlite x.y.z [:memory:]
Grouped by: Species
Ordered by: Sepal.Length

# S3: tbl_dbi
# A tibble: ?? x 5
# Source:
# table<iris-output-test>
# [?? x 5]
# Database: sqlite x.y.z
# [:memory:]
# Groups: Species
# Ordered by: Sepal.Length
Sepal.Length Sepal.Width
<dbl> <dbl>
1 4.3 3.0
Expand Down
11 changes: 5 additions & 6 deletions tests/testthat/output/iris-head-30-80.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Source: lazy query [?? x 5]
Database: sqlite x.y.z [:memory:]
Grouped by: Species
Ordered by: Sepal.Length

# S3: tbl_dbi
# A tibble: ?? x 5
# Source: lazy query [?? x 5]
# Database: sqlite x.y.z [:memory:]
# Groups: Species
# Ordered by: Sepal.Length
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
<dbl> <dbl> <dbl> <dbl> <chr>
1 4.3 3.0 1.1 0.1 setosa
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/output/mtcars-8-30.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Source: table<mtcars-output-test> [?? x 11]
Database: sqlite x.y.z [:memory:]

# S3: tbl_dbi
# A tibble: ?? x 11
# Source:
# table<mtcars-output-test>
# [?? x 11]
# Database: sqlite x.y.z
# [:memory:]
mpg cyl disp hp
<dbl> <dbl> <dbl> <dbl>
1 21.0 6 160.0 110
Expand Down

0 comments on commit 388c001

Please sign in to comment.