Skip to content

Commit

Permalink
bug fix with print.look_for() (#149)
Browse files Browse the repository at this point in the history
* big fix with `print.look_for()`

avoid an error when console pane is physically shrunk too small

fix #148

* a col was missing when computing lw
  • Loading branch information
larmarange authored Aug 15, 2023
1 parent 4ae9dbd commit e908107
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
`.null_action` argument to `set_value_labels()`, `add_value_labels()` and
`remove_value_labels()` (#145)

**Bug fix**

* avoid an error with `print.look_for()` when console pane is physically shrunk
too small (#148)

# labelled 2.12.0

**New features**
Expand Down
7 changes: 5 additions & 2 deletions R/lookfor.R
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,21 @@ print.look_for <- function(x, ...) {
if ("values" %in% names(x)) {
w_col_type <- max(8, stringr::str_length(x$col_type))
w_values <- max(5, stringr::str_length(x$values)) # nolint
w_missing <- max(7, stringr::str_length(x$missing))
# width for labels
lw <- w - 8 - w_pos - w_variable - w_col_type
lw <- w - 8 - w_pos - w_variable - w_col_type - w_missing
lw <- dplyr::case_when(
w_values < lw / 2 ~ lw - w_values,
w_label < lw / 2 ~ lw - w_label,
TRUE ~ trunc(lw / 2)
)
# a minimum of 10
lw <- max(10, lw)
x$label <- stringr::str_trunc(x$label, lw, ellipsis = "~")
x$values <- stringr::str_trunc(x$values, lw, ellipsis = "~")
} else {
# width for labels
lw <- w - 4 - w_pos - w_variable
lw <- max(10, lw)
x$label <- stringr::str_trunc(x$label, lw, ellipsis = "~")
}

Expand Down

0 comments on commit e908107

Please sign in to comment.