19
19
# '
20
20
# ' @examples
21
21
# ' paleta_create_sequential(n = 5, org = "acdc", name = "blues")
22
+ # ' paleta_create_divergent(n = 5, org = "acdc", name = "rdylgn")
22
23
# '
23
24
# ' @rdname create_paleta
24
25
# ' @export
25
26
# '
26
27
27
- paleta_create_sequential <- function (n , org , name ) {
28
+ paleta_create_sequential <- function (n ,
29
+ org = c(" acdc" , " nhs" ),
30
+ name ) {
31
+ # # Get org ----
32
+ org <- match.arg(org )
33
+
28
34
# # Check if specified palette is found in specified org palette ----
29
35
paleta_check_colour(name = name , org = org )
30
36
@@ -34,17 +40,21 @@ paleta_create_sequential <- function(n, org, name) {
34
40
# # Check if number of colours is compatible with sequential ----
35
41
if (n < 3 ) {
36
42
cli :: cli_bullets(
37
- " !" = " Sequential palettes have minimum 3 colours" ,
38
- " i" = " Returning 3 colours"
43
+ c(
44
+ " !" = " Sequential palettes have minimum 3 colours" ,
45
+ " i" = " Returning 3 colours"
46
+ )
39
47
)
40
48
41
49
n <- 3
42
50
}
43
51
44
52
if (n > 9 ) {
45
53
cli :: cli_bullets(
46
- " !" = " Sequential palettes have maximum 9 colours" ,
47
- " i" = " Returning 9 colours"
54
+ c(
55
+ " !" = " Sequential palettes have maximum 9 colours" ,
56
+ " i" = " Returning 9 colours"
57
+ )
48
58
)
49
59
50
60
n <- 9
@@ -56,6 +66,15 @@ paleta_create_sequential <- function(n, org, name) {
56
66
# # Update palette to n ----
57
67
pal <- grDevices :: colorRampPalette(pal )(n )
58
68
69
+ cli :: cli_bullets(
70
+ c(
71
+ c(
72
+ " v" = " Sequential colour palette successfully created" ,
73
+ " i" = " Sequential palette: {pal}"
74
+ )
75
+ )
76
+ )
77
+
59
78
# # Create palette class ----
60
79
class(pal ) <- " palette"
61
80
@@ -78,17 +97,21 @@ paleta_create_divergent <- function(n, name, org) {
78
97
# # Check if number of colours is compatible with divergent ----
79
98
if (n < 3 ) {
80
99
cli :: cli_bullets(
81
- " !" = " Divergent palettes have minimum 3 colours" ,
82
- " i" = " Returning 3 colours"
100
+ c(
101
+ " !" = " Divergent palettes have minimum 3 colours" ,
102
+ " i" = " Returning 3 colours"
103
+ )
83
104
)
84
105
85
106
n <- 3
86
107
}
87
108
88
109
if (n > 11 ) {
89
110
cli :: cli_bullets(
90
- " !" = " Divergent palettes have maximum 11 colours" ,
91
- " i" = " Returning 11 colours"
111
+ c(
112
+ " !" = " Divergent palettes have maximum 11 colours" ,
113
+ " i" = " Returning 11 colours"
114
+ )
92
115
)
93
116
94
117
n <- 11
@@ -100,6 +123,13 @@ paleta_create_divergent <- function(n, name, org) {
100
123
# # Update palette to n ----
101
124
pal <- grDevices :: colorRampPalette(pal )(n )
102
125
126
+ cli :: cli_bullets(
127
+ c(
128
+ " v" = " Divergent colour palette successfully created" ,
129
+ " i" = " Divergent palette: {pal}"
130
+ )
131
+ )
132
+
103
133
# # Create palette class ----
104
134
class(pal ) <- " palette"
105
135
@@ -124,8 +154,10 @@ paleta_create_qualitative <- function(n, name, org) {
124
154
# # Check that n is not more than length(pal) ----
125
155
if (n > length(pal )) {
126
156
cli :: cli_bullets(
127
- " !" = " {.code n = {n}} is greater than available colours in {name} palette" ,
128
- " i" = " Returning all colours in {name} colour palette"
157
+ c(
158
+ " !" = " {.code n = {n}} is greater than available colours in {name} palette" ,
159
+ " i" = " Returning all colours in {name} colour palette"
160
+ )
129
161
)
130
162
131
163
n <- length(pal )
@@ -222,13 +254,9 @@ paleta_check_type <- function(name,
222
254
cli :: cli_abort(
223
255
" {name} is not a {pal_type} colour palette"
224
256
)
225
-
226
- FALSE
227
257
} else {
228
258
cli :: cli_alert_success(
229
259
" {name} is a {pal_type} colour palette"
230
260
)
231
-
232
- TRUE
233
261
}
234
262
}
0 commit comments