Skip to content

Commit

Permalink
use non-breaking space to keep name and type together
Browse files Browse the repository at this point in the history
but substitute by regular space afterwards

@hadley: I hope this is "portable enough" for our purposes -- the CRAN tests will show.
  • Loading branch information
Kirill Müller committed May 7, 2016
1 parent 51f5693 commit 46bd4c8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
5 changes: 4 additions & 1 deletion R/utils-format.r
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ format_extra_rows <- function(x) {

format_extra_cols <- function(x) {
if (length(x$extra) > 0) {
var_types <- paste0(names(x$extra), " <", x$extra, ">")
var_types <- paste0(names(x$extra), NBSP, "<", x$extra, ">")
if (x$n_extra > 0) {
if (x$n_extra < length(var_types)) {
var_types <- c(var_types[seq_len(x$n_extra)], "...")
Expand Down Expand Up @@ -200,10 +200,13 @@ knit_print.trunc_mat <- function(x, options) {
knitr::asis_output(res)
}

NBSP <- "\U00A0"

wrap <- function(..., indent = 0, width) {
x <- paste0(..., collapse = "")
wrapped <- strwrap(x, indent = indent, exdent = indent + 2,
width = width)
wrapped <- gsub(NBSP, " ", wrapped)

paste0(wrapped, collapse = "\n")
}
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/output/trunc_mat/all--30.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<dbl> <int> <lgl> <chr>
1 1.0 1 TRUE a
2 2.5 2 FALSE b
... with 4 more variables: e
<fctr>, f <date>, g <time>,
h <list>
... with 4 more variables:
e <fctr>, f <date>,
g <time>, h <list>
4 changes: 2 additions & 2 deletions tests/testthat/output/trunc_mat/all-1-30-2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<dbl> <int> <lgl> <chr>
1 1 1 TRUE a
... with 1 more rows, and 4
more variables: e <fctr>, f
<date>, ...
more variables: e <fctr>,
f <date>, ...
12 changes: 4 additions & 8 deletions tests/testthat/output/trunc_mat/iris-3-5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
4
more
variables:
Sepal.Width
<dbl>,
Petal.Length
<dbl>,
Petal.Width
<dbl>,
Species
<fctr>
Sepal.Width <dbl>,
Petal.Length <dbl>,
Petal.Width <dbl>,
Species <fctr>
4 changes: 2 additions & 2 deletions tests/testthat/output/trunc_mat/iris-5-30.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
... with 145 more rows, and 3
more variables:
Petal.Length <dbl>,
Petal.Width <dbl>, Species
<fctr>
Petal.Width <dbl>,
Species <fctr>
6 changes: 3 additions & 3 deletions tests/testthat/output/trunc_mat/mtcars-8-30.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
8 24.4 4 146.7 62
... with 24 more rows, and 7
more variables: drat <dbl>,
wt <dbl>, qsec <dbl>, vs
<dbl>, am <dbl>, gear
<dbl>, carb <dbl>
wt <dbl>, qsec <dbl>,
vs <dbl>, am <dbl>,
gear <dbl>, carb <dbl>
4 changes: 2 additions & 2 deletions tests/testthat/output/trunc_mat/mtcars-knit-60.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
|22.8 |4 |140.8 |95 |3.92 |3.150 |22.90 |1 |0 |
|19.2 |6 |167.6 |123 |3.92 |3.440 |18.30 |1 |0 |

(with 22 more rows, and 2 more variables: gear <dbl>, carb
<dbl>)
(with 22 more rows, and 2 more variables: gear <dbl>,
carb <dbl>)

0 comments on commit 46bd4c8

Please sign in to comment.