Skip to content

Commit

Permalink
Merge branch 'f-#98-glimpse-paren'. Fixes #98. @hadley: PTAL.
Browse files Browse the repository at this point in the history
- `glimpse()` shows nesting structure for lists (#98).
  • Loading branch information
Kirill Müller committed Jun 20, 2016
2 parents dfd3d07 + 96c1d15 commit 9fca89e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ S3method(as_data_frame,table)
S3method(as_data_frame,tbl_df)
S3method(format_v,character)
S3method(format_v,default)
S3method(format_v,list)
S3method(glimpse,data.frame)
S3method(glimpse,default)
S3method(glimpse,tbl)
Expand Down
14 changes: 14 additions & 0 deletions R/glimpse.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,21 @@ str_trunc <- function(x, max_width) {
}

format_v <- function(x) UseMethod("format_v")

#' @export
format_v.default <- function(x) format(x, trim = TRUE, justify = "none")

#' @export
format_v.list <- function(x) {
x <- lapply(x, format_v)
atomic <- vapply(x, length, integer(1L)) == 1L
x <- vapply(x, function(x) paste(x, collapse = ", "), character(1L))
x[!atomic] <- paste0("<", x[!atomic], ">")
if (length(x) == 1L)
x
else
paste0("[", paste(x, collapse = ", "), "]")
}

#' @export
format_v.character <- function(x) encodeString(x, quote = '"')
4 changes: 2 additions & 2 deletions tests/testthat/output/glimpse/all-50.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ $ d (chr) "a", "b", NA
$ e (fctr) a, b, NA
$ f (date) 2015-12-10, 2015-12-11, NA
$ g (time) 2015-12-09 10:51:35, 2015-12-09 10...
$ h (list) 1, 2, NA
$ i (list) 1, 2, 3, 4, 5, 6, NA
$ h (list) [1, 2, NA]
$ i (list) [[1, <2, 3>], <4, 5, 6>, NA]
4 changes: 2 additions & 2 deletions tests/testthat/output/glimpse/all-70.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ $ d (chr) "a", "b", NA
$ e (fctr) a, b, NA
$ f (date) 2015-12-10, 2015-12-11, NA
$ g (time) 2015-12-09 10:51:35, 2015-12-09 10:51:36, NA
$ h (list) 1, 2, NA
$ i (list) 1, 2, 3, 4, 5, 6, NA
$ h (list) [1, 2, NA]
$ i (list) [[1, <2, 3>], <4, 5, 6>, NA]

0 comments on commit 9fca89e

Please sign in to comment.