Skip to content

Commit

Permalink
use a regular expression \\U to capitalize the first letter
Browse files Browse the repository at this point in the history
an alternative way is a loop:

  for (i in c("design", "n", "event", "time", "bound", "power")) {
    # special case: Event -> Events
    names(ans)[names(ans) == i] <- if (i == "event") "Events" else {
      # capitalize the first letter
      sub("^(.)", "\\U\\1", i, perl = TRUE)
    }
  }
  • Loading branch information
yihui committed Aug 30, 2024
1 parent b26ed32 commit 59047f3
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,14 @@ summary.fixed_design <- function(object, ...) {
), fixed = TRUE)
)

ans <- x$analysis %>% mutate(design = x_design)
ans <- ans %>% dplyr::rename(Design = design)

if ("n" %in% names(ans)) {
ans <- ans %>% dplyr::rename(N = n)
}

if ("event" %in% names(ans)) {
ans <- ans %>% dplyr::rename(Events = event)
}

if ("time" %in% names(ans)) {
ans <- ans %>% dplyr::rename(Time = time)
}

if ("bound" %in% names(ans)) {
ans <- ans %>% dplyr::rename(Bound = bound)
}

if ("power" %in% names(ans)) {
ans <- ans %>% dplyr::rename(Power = power)
}
ans <- within(x$analysis, design <- x_design)
nms <- c("design", "n", "event", "time", "bound", "power")
i <- names(ans) %in% nms
# capitalize the first letter
names(ans)[i] <- sub("^(.)", "\\U\\1", names(ans)[i], perl = TRUE)
# special case: Event -> Events
i <- names(ans) == "Event"
names(ans)[i] <- "Events"

class(ans) <- c("fixed_design", x$design, class(ans))
return(ans)
Expand Down

0 comments on commit 59047f3

Please sign in to comment.