File: rccValidators.R

package info (click to toggle)
r-cran-r.methodss3 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 300 kB
  • sloc: sh: 12; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 1,126 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
rccValidateFunctionName <- function(name, ...) {
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Validate 'name'
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Assert that the generic function name is a valid function name.
  firstLetter <- substring(gsub("^[.]*", "", name), 1,1)

  allowedFirst <- c("?", "$", "$<-", "[", "[<-", "[[", "[[<-")
  allowedFirst <- c(allowedFirst, "+", "-", "*", "^", "%")
  if (!is.element(firstLetter, allowedFirst)) {
    if (!is.element(tolower(firstLetter), letters))
      stop("Except for a few operators, method/function names must begin with a letter: ", name)

    # Check first letter  
    if (firstLetter == toupper(firstLetter))
      stop("Method/function names should start with a lower case letter: ", name)
  }
}
export(rccValidateFunctionName) <- FALSE

rccValidateSetMethodS3 <- function(name, ...) {
  rccValidateFunctionName(name=name)
}
export(rccValidateSetMethodS3) <- FALSE

rccValidateSetGenericS3 <- function(name, ...) {
  rccValidateFunctionName(name=name)
}
export(rccValidateSetGenericS3) <- FALSE