File: checks.r

package info (click to toggle)
r-cran-stringr 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 304 kB
  • sloc: makefile: 3
file content (22 lines) | stat: -rw-r--r-- 622 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
# Check that stringr is of the correct type for stringr functions
check_string <- function(string) {
  if (!is.atomic(string)) 
    stop("String must be an atomic vector", call. = FALSE)
  
  if (!is.character(string)) 
    string <- as.character(string)
  
  string
}

# Check that pattern is of the correct type for stringr functions
check_pattern <- function(pattern, string, replacement = NULL) {
  if (!is.character(pattern)) 
    stop("Pattern must be a character vector", call. = FALSE)
  
  if (!recyclable(string, pattern, replacement)) {
    stop("Lengths of string and pattern not compatible")
  }

  pattern
}