@@ -33,7 +33,7 @@ adsl$TRTA <- factor(adsl$TRTA,
33
33
labels = c("Placebo", "Low Dose", "High Dose")
34
34
)
35
35
36
- meta <- meta_adam(
36
+ meta_sl <- meta_adam(
37
37
population = adsl,
38
38
observation = adsl
39
39
) |>
@@ -85,13 +85,42 @@ In this vignette, we will directly use the metadata built by `meta_ae_example()`
85
85
meta_ae <- meta_ae_example()
86
86
```
87
87
88
+ ## Customization (Optional)
89
+
90
+ If you want to capitalize only the first letter of "RACE" (e.g., Black or african american) or any other character variable,
91
+ you can customize the ` react_base_char ` function at the beginning of the code.
92
+
93
+
94
+ ``` {r}
95
+ # function to capitalize the first letter of a string that has multiple words
96
+ capitalize_words <- function(x) {
97
+ sapply(x, function(word) {
98
+ paste0(toupper(substr(word, 1, 1)), tolower(substr(word, 2, nchar(word))))
99
+ })
100
+ }
101
+ ```
102
+
103
+ ``` {r}
104
+ # 1) In "data_population": extract the RACE values as a character vector
105
+ race_values_pop <- meta_sl[["data_population"]]$RACE # Use $ to get a vector
106
+
107
+ # Capitalize the race values
108
+ meta_sl[["data_population"]]$RACE <- capitalize_words(race_values_pop) # Assign back as a vector
109
+
110
+ # 2) In "data_observation": extract the RACE values as a character vector
111
+ race_values_obs <- meta_sl[["data_observation"]]$RACE # Use $ to get a vector
112
+
113
+ # Capitalize the race values
114
+ meta_sl[["data_observation"]]$RACE <- capitalize_words(race_values_obs) # Assign back as a vector
115
+ ```
116
+
88
117
# Build a reactable {.tabset}
89
118
90
119
## Baseline characteristic table + Participants With Drug-Related AE
91
120
92
121
``` {r, eval = TRUE}
93
122
react_base_char(
94
- metadata_sl = meta ,
123
+ metadata_sl = meta_sl ,
95
124
metadata_ae = meta_ae,
96
125
ae_subgroup = c("age", "race", "gender"),
97
126
ae_specific = "rel",
@@ -103,75 +132,10 @@ react_base_char(
103
132
104
133
``` {r, eval=TRUE}
105
134
react_base_char(
106
- metadata_sl = meta ,
135
+ metadata_sl = meta_sl ,
107
136
metadata_ae = meta_ae,
108
137
ae_subgroup = c("age", "race", "gender"),
109
138
ae_specific = "ser",
110
139
width = 1200
111
140
)
112
141
```
113
-
114
- ## Customization
115
-
116
- If you want to capitalize the first letter of each word in the "RACE" (Black or African American) or any other character variable,
117
- you can customize the ` react_base_char ` function at the beginning of the code.
118
-
119
- ``` {r, eval = FALSE}
120
- # function to capitalize the first letter of each word (proper case)
121
- capitalize_words <- function(x) {
122
- # Define a vector of words to be lower-cased for minor words like articles, conjunctions, and propositions
123
- lowercase_exceptions <- c(
124
- "a", "an", "the", "and", "or", "but", "for", "nor", "on", "so",
125
- "yet", "at", "to", "by", "with", "in", "of", "as", "up", "with"
126
- )
127
-
128
- sapply(x, function(sentence) {
129
- # Split the sentence into words
130
- words <- strsplit(sentence, " ")[[1]]
131
-
132
- # Capitalize the first letter of each word, except for exceptions
133
- capitalized_words <- sapply(seq_along(words), function(i) {
134
- word <- words[i]
135
- if (i == 1 || !(tolower(word) %in% lowercase_exceptions)) {
136
- # Capitalize the first letter if it's the first word or not an exception
137
- paste0(toupper(substr(word, 1, 1)), tolower(substr(word, 2, nchar(word))))
138
- } else {
139
- # Return the word in lowercase if it's an exception
140
- tolower(word)
141
- }
142
- })
143
-
144
- # Combine the capitalized words back into a single string
145
- paste(capitalized_words, collapse = " ")
146
- })
147
- }
148
- ```
149
- If you want to capitalize only the first letter of "RACE" (e.g., Black or african american) or any other character variable,
150
- you can customize the ` react_base_char ` function at the beginning of the code.
151
-
152
-
153
- ``` {r, eval = FALSE}
154
- # function to capitalize the first letter of a string that has multiple words
155
- capitalize_words <- function(x) {
156
- sapply(x, function(word) {
157
- paste0(toupper(substr(word, 1, 1)), tolower(substr(word, 2, nchar(word))))
158
- })
159
- }
160
- ```
161
- The first function capitalizes the first letter of each word, while the second function capitalizes only the first letter of a string that contains multiple words.
162
-
163
- Use either of the “capitalize_words” functions above to meet your needs. Example below is the implementation of the first function.
164
-
165
- ``` {r, eval = FALSE}
166
- # 1) In "data_population": extract the RACE values as a character vector
167
- race_values_pop <- metadata_sl[["data_population"]]$RACE # Use $ to get a vector
168
-
169
- # Capitalize the race values
170
- metadata_sl[["data_population"]]$RACE <- capitalize_words(race_values_pop) # Assign back as a vector
171
-
172
- # 2) In "data_observation": extract the RACE values as a character vector
173
- race_values_obs <- metadata_sl[["data_observation"]]$RACE # Use $ to get a vector
174
-
175
- # Capitalize the race values
176
- metadata_sl[["data_observation"]]$RACE <- capitalize_words(race_values_obs) # Assign back as a vector
177
- ```
0 commit comments