Skip to content

Commit

Permalink
Print long spec declarations properly (#598)
Browse files Browse the repository at this point in the history
Fixes #597
  • Loading branch information
jimhester committed Feb 8, 2017
1 parent be93d4c commit 1b590b5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,5 +1,7 @@
# readr 1.0.0.9000

* Long spec declarations now print properly (#597).

* parsing problems in `read_delim()` and `read_fwf()` when columns are skipped using col_types now report the correct column name (#573, @cb4ds)

* `parse_time()` now correctly handles 12 AM/PM (#579).
Expand Down
2 changes: 1 addition & 1 deletion R/col_types.R
Expand Up @@ -135,7 +135,7 @@ format.col_spec <- function(x, n = Inf, condense = NULL, ...) {
vapply(seq_along(cols),
function(i) {
col_funs <- sub("^collector_", "col_", class(cols[[i]])[[1]])
args <- vapply(cols[[i]], deparse, character(1))
args <- vapply(cols[[i]], deparse2, character(1), sep = "\n ")
args <- paste(names(args), args, sep = " = ", collapse = ", ")

col_names <- names(cols)[[i]]
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Expand Up @@ -15,3 +15,7 @@ show_progress <- function() {
!interactive() || # not an interactive session
!is.null(getOption("knitr.in.progress")) # Not actively knitting a document
}

deparse2 <- function(expr, ..., sep = "\n") {
paste(deparse(expr, ...), collapse = sep)
}
9 changes: 9 additions & 0 deletions tests/testthat/test-col-spec.R
Expand Up @@ -217,3 +217,12 @@ test_that("non-syntatic names are escaped", {
)
")
})

test_that("long expressions are wrapped (597)", {
expect_equal(format(cols(a = col_factor(levels = c("apple", "pear", "banana", "peach", "apricot", "orange", "plum"), ordered = TRUE))),
'cols(
a = col_factor(levels = c("apple", "pear", "banana", "peach", "apricot", "orange", "plum"
), ordered = TRUE)
)
')
})

0 comments on commit 1b590b5

Please sign in to comment.