Skip to content

Commit 285eb28

Browse files
committed
Control view length with an option
1 parent a9760eb commit 285eb28

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

R/view.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ str_view_widget <- function(lines) {
168168
}
169169

170170
#' @export
171-
print.stringr_view <- function(x, ..., n = 20) {
171+
print.stringr_view <- function(x, ..., n = getOption("stringr.view_n", 20)) {
172172
n_extra <- length(x) - n
173173
if (n_extra > 0) {
174174
x <- x[seq_len(n)]

tests/testthat/_snaps/view.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
[20] | again
2626
... and 960 more
2727

28+
---
29+
30+
Code
31+
str_view(words)
32+
Output
33+
[1] | a
34+
[2] | able
35+
[3] | about
36+
[4] | absolute
37+
[5] | accept
38+
... and 975 more
39+
2840
# indices come from original vector
2941

3042
Code

tests/testthat/test-view.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
test_that("results are truncated", {
22
expect_snapshot(str_view(words))
3+
4+
# and can control with option
5+
local_options(stringr.view_n = 5)
6+
expect_snapshot(str_view(words))
37
})
48

59
test_that("indices come from original vector", {

0 commit comments

Comments
 (0)