File: zzz.R

package info (click to toggle)
r-cran-httpcode 0.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 164 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 720 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
msg_format <-
  "<Status code: %s>
  Message: %s
  Explanation: %s,
  Verbose Explanation: %s"

msg_list <- function(a, b, c, d){
  comp(list(
    status_code = a,
    message = b,
    explanation = c,
    verbose_explanation = d
  ))
}

is_three_digit_code <- function(x) grepl("\\d{3}", x)

nozero <- function(x) names(x[sapply(x, length) > 0])

stopcode <- function(x, y) stop(sprintf('%s: %s\n', x, y), call. = FALSE)

`%||%` <- function(x, y) if (is.null(x)) y else x

comp <- function(l) Filter(Negate(is.null), l)

assert <- function(x, y) {
  if (!is.null(x)) {
    if (!inherits(x, y)) {
      stop(deparse(substitute(x)), " must be of class ",
           paste0(y, collapse = ", "), call. = FALSE)
    }
  }
}