File: utils.R

package info (click to toggle)
r-cran-rotl 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,384 kB
  • sloc: sh: 9; makefile: 5
file content (47 lines) | stat: -rw-r--r-- 800 bytes parent folder | download
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
rotl_is_flag <- function(x) {
  identical(length(x), 1L) && 
  rlang::is_bare_logical(x) &&
    !is.na(x)
    
}

rotl_is_string <- function(x) {
  identical(length(x), 1L) && 
  rlang::is_bare_character(x) &&
    !is.na(x)    
}

check_factory <- function(f, x, arg_name, msg) {
  if (f(x)) {
    return(TRUE)    
  }
  
  stop(
    paste0(
      "Argument ",
      sQuote(arg_name),
      msg
    ),
    call. = FALSE
  )
}

check_is_flag <- function(x) {
  arg_name <- deparse(substitute(x))
  check_factory(
    rotl_is_flag,
    x,
    arg_name,
    " is not a flag (a length one logical vector)."
  )
}

check_is_string <- function(x) {
  arg_name <- deparse(substitute(x))
  check_factory(
    rotl_is_string,
    x,
    arg_name,
    " is not a string (a length one character vector)."
  )
}