Skip to content

Commit 4aa7e4a

Browse files
committed
update example
1 parent ebe516a commit 4aa7e4a

File tree

1 file changed

+32
-68
lines changed

1 file changed

+32
-68
lines changed

vignettes/interactive-baseline.Rmd

Lines changed: 32 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ adsl$TRTA <- factor(adsl$TRTA,
3333
labels = c("Placebo", "Low Dose", "High Dose")
3434
)
3535
36-
meta <- meta_adam(
36+
meta_sl <- meta_adam(
3737
population = adsl,
3838
observation = adsl
3939
) |>
@@ -85,13 +85,42 @@ In this vignette, we will directly use the metadata built by `meta_ae_example()`
8585
meta_ae <- meta_ae_example()
8686
```
8787

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+
88117
# Build a reactable {.tabset}
89118

90119
## Baseline characteristic table + Participants With Drug-Related AE
91120

92121
```{r, eval = TRUE}
93122
react_base_char(
94-
metadata_sl = meta,
123+
metadata_sl = meta_sl,
95124
metadata_ae = meta_ae,
96125
ae_subgroup = c("age", "race", "gender"),
97126
ae_specific = "rel",
@@ -103,75 +132,10 @@ react_base_char(
103132

104133
```{r, eval=TRUE}
105134
react_base_char(
106-
metadata_sl = meta,
135+
metadata_sl = meta_sl,
107136
metadata_ae = meta_ae,
108137
ae_subgroup = c("age", "race", "gender"),
109138
ae_specific = "ser",
110139
width = 1200
111140
)
112141
```
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

Comments
 (0)