-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialChar.R
executable file
·34 lines (31 loc) · 1.42 KB
/
initialChar.R
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
initialChar <- function(
txt, # Text to parse.
adm = "[:lower:]", # Acceptable values for the output.
err = "Not acceptable value" # Error message if not in the acceptable values.
){
###############################################################################
# Mango Solutions, Chippenham SN14 0SQ 2006
# initialChar.R Fri Sun Jun 03 20:05:15 BST 2007 @836 /Internet Time/
#
# Author: Romain
###############################################################################
# DESCRIPTION: gets the first letter from a character string and "lower case" it
# KEYWORDS: check, component:support
###############################################################################
# Tidy up the input.
if(missing(txt) || is.null(txt) || length(txt) == 0)
ectdStop("no character string to use")
if(length(txt) > 1)
ectdWarning("only the first element has been used")
txt <- as.character( txt[1] )
# Figure out where is the first letter in that string and extract it.
re <- regexpr("[[:alpha:]]", txt)
if(re == -1)
ectdStop("No character in the string")
out <- casefold( substring(txt,re,re ) )
# Checks if the output is one of the possibilities given.
rx <- paste("[", casefold(adm) , "]", sep = "")
if( out %!~% rx )
ectdStop( err )
out
}