File: internal.R

package info (click to toggle)
r-cran-assertive.base 0.0-9-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 476 kB
  • sloc: sh: 13; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 815 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
merge.NULL <- function(x, y, ...)
{
  return(y)
}

names_never_null <- function(x)
{
  nms <- names(x)
  if(is.null(nms))
  {
    nms <- character(length(x))
  }  
  nms
}

#' Truncate a string
#' 
#' Truncates a character vector to have a maximum length.
#' @param x A character vector, or something coercible to one.
#' @param width A positive integer.
#' @return A character vector
#' @seealso \code{\link[base]{abbreviate}}
#' @examples
#' assertive.base:::truncate(c("abcd", "efghi", "jklmno", "pqrstuv"), 5)
#' @noRd
truncate <- function(x, width = getOption("width"))
{
  x <- as.character(x)
  ifelse(
    nchar(x) > width,
    # paste0(substring(x, 1, width - 1), "\u2026") would be better, but some
    # setups don't display unicode properly.
    paste0(substring(x, 1, width - 3), "..."),
    x
  )
}