File: helper-output.R

package info (click to toggle)
r-cran-pillar 1.8.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,840 kB
  • sloc: sh: 13; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
show_output_in_terminal <- function() {
  system2("xterm", c("-e", shQuote("head tests/testthat/out/*; sleep 600")))
}

# A data frame with all major types
df_all <- pillar:::new_tbl(list(
  a = c(1, 2.5, NA),
  b = c(1:2, NA),
  c = c(T, F, NA),
  d = c("a", "b", NA),
  e = factor(c("a", "b", NA)),
  f = as.Date("2015-12-09") + c(1:2, NA),
  g = as.POSIXct("2015-12-09 10:51:34.5678", tz = "UTC") + c(1:2, NA),
  h = as.list(c(1:2, NA)),
  i = list(list(1, 2:3), list(4:6), list(NA))
))

# A data frame with strings of varying lengths
long_str <- strrep("Abcdefghij", 5)
df_str <- pillar:::map(rlang::set_names(1:50), function(i) substr(long_str, 1, i))

#' `add_special()` is not exported, and used only for initializing default
#' values to `expect_pillar_output()`.
#' @rdname expect_pillar_output
add_special <- function(x) {
  if (inherits(x, "integer64")) {
    x <- c(x, bit64::NA_integer64_)
  } else {
    x <- x[seq2(1, length(x) + 1)]
    if (is.numeric(x) && is.double(x)) {
      x <- c(x, -Inf, Inf)
    }
  }
  x
}

continue <- function(x) {
  paste0(x, symbol$continue)
}

# from pkgdepends
local_colors <- function(.local_envir = parent.frame()) {
  # This is to restore crayon's cache. This runs after restoring the options.
  withr::defer(envir = .local_envir, {
    num_colors(forget = TRUE)
  })

  # We run this first, so this will run last by withr, to restore the
  # original options.
  withr::local_options(
    list(cli.num_colors = 16L),
    .local_envir = .local_envir
  )

  # Added safety
  num_colors(forget = TRUE)
}

local_utf8 <- function(enable = TRUE, .local_envir = parent.frame()) {
  withr::local_options(
    list(cli.unicode = enable),
    .local_envir = .local_envir
  )
}