You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (identical(toupper(convert_to), "ORDINAL_NUMBER")) {
33
-
34
-
if (!toupper(language) %in%supported_languages_ordinal_number) stop(paste("Language supplied (", language, ") is currently not supported by toOrdinal for conversion to an 'ordinal_number'. Currently supported languages include: ", paste(supported_languages_ordinal_number, collapse=", "), ". Please submit pull requests to https://github.com/CenterForAssessment/toOrdinal/pulls for additional language support.", sep=""), call.=FALSE)
35
-
36
-
37
-
### DUTCH
38
-
39
-
if (toupper(language)=="DUTCH") {
40
-
tmp<- strtail(as.character(cardinal_number), 2)
41
-
tmp.suffix<-"ste"
42
-
if (tmp%in% c('8', paste(0, 8, sep=""))) tmp.suffix<-"ste"
43
-
if (tmp%in% c('1', paste(c(0, 2:9), 1, sep=""))) tmp.suffix<-"ste"
44
-
if (tmp%in% c(0, 2:7, 9, paste(0, c(2:7,9) , sep=""))) tmp.suffix<-"de"
45
-
if (tmp%in% paste(1, 0:9 , sep="")) tmp.suffix<-"de"
46
-
}
47
-
48
-
49
-
### ENGLISH
50
-
51
-
if (toupper(language)=="ENGLISH") {
52
-
tmp<- strtail(as.character(cardinal_number), 2)
53
-
if (tmp%in% c('1', paste(c(0, 2:9), 1, sep=""))) tmp.suffix<-"st"
54
-
if (tmp%in% c('2', paste(c(0, 2:9), 2, sep=""))) tmp.suffix<-"nd"
55
-
if (tmp%in% c('3', paste(c(0, 2:9), 3, sep=""))) tmp.suffix<-"rd"
56
-
if (tmp%in% c('11', '12', '13')) tmp.suffix<-"th"
57
-
if (tmp%in% c('4', paste(0:9, 4, sep=""))) tmp.suffix<-"th"
58
-
if (tmp%in% c('5', paste(0:9, 5, sep=""))) tmp.suffix<-"th"
59
-
if (tmp%in% c('6', paste(0:9, 6, sep=""))) tmp.suffix<-"th"
60
-
if (tmp%in% c('7', paste(0:9, 7, sep=""))) tmp.suffix<-"th"
61
-
if (tmp%in% c('8', paste(0:9, 8, sep=""))) tmp.suffix<-"th"
62
-
if (tmp%in% c('9', paste(0:9, 9, sep=""))) tmp.suffix<-"th"
63
-
if (tmp%in% c('0', paste(0:9, 0, sep=""))) tmp.suffix<-"th"
64
-
}
65
-
66
-
67
-
### FRENCH
68
-
69
-
if (toupper(language)=="FRENCH") {
70
-
if (cardinal_number==1) tmp.suffix<-"re"elsetmp.suffix<-"e"
71
-
}
72
-
73
-
74
-
### GERMAN (standard method of adding a suffix "." to the number)
75
-
76
-
if (toupper(language)=="GERMAN_ALT") {
77
-
if (cardinal_number>=0) tmp.suffix<-"."
78
-
}
79
-
80
-
81
-
### GERMAN (informal *te and *ste endings)
82
-
83
-
if (toupper(language)=="GERMAN") {
84
-
if (cardinal_number>=0&cardinal_number<=19) tmp.suffix<-"te"
if (identical(toupper(convert_to), "ORDINAL_WORD")) {
128
-
129
-
if (!toupper(language) %in%supported_languages_ordinal_word) stop(paste("Language supplied (", language, ") is currently not supported by toOrdinal for conversion to an 'ordinal_word'. Currently supported languages include: ", paste(supported_languages_ordinal_word, collapse=", "), ". Please submit pull requests to https://github.com/CenterForAssessment/toOrdinal/pulls for additional language support.", sep=""), call.=FALSE)
130
-
131
-
132
-
### ENGLISH
133
-
134
-
135
-
136
-
137
-
} ### if (identical(toupper(convert_to), "ORDINAL_WORD"))
138
-
} ### END toOrdinal
139
-
140
-
###
141
94
### toOrdinalDate_INTERNAL
142
-
###
143
95
`toOrdinalDate_INTERNAL`<-
144
96
function(
145
97
date=NULL,
146
98
language="English") {
147
99
148
-
149
100
### ENGLISH
150
101
151
102
if (toupper(language)=="ENGLISH") {
@@ -155,4 +106,80 @@ function(
155
106
156
107
### OTHER LANGUAGES
157
108
158
-
} ### END toOrdinalDate
109
+
} ### END toOrdinalDate_INTERNAL
110
+
111
+
### strTail
112
+
`strTail`<-
113
+
function(
114
+
string,
115
+
n_char=1) {
116
+
117
+
# Ensure n_char is an integer and within valid bounds
118
+
if (!is.numeric(n_char) ||n_char!= as.integer(n_char)) {
119
+
stop("n_char must be an integer.")
120
+
}
121
+
122
+
# Apply the function to each element of the vector
123
+
result<- sapply(string, function(str) {
124
+
if (!is.character(str)) stop("Each element must be a character string.")
125
+
126
+
string_len<- nchar(str)
127
+
128
+
if (abs(n_char) >string_len&&n_char>0) n_char<-string_len
129
+
if (abs(n_char) >string_len&&n_char<0) n_char<--string_len
0 commit comments