Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace datawizard::data_rename #474

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions R/report_sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,21 @@
unique(groups),
new_column = ".old_names",
separator = "."
)[[".old_names"]]
)[".old_names"]

new_names <- datawizard::data_unite(
unique(groups),
new_column = ".new_names",
separator = ", "
)[[".new_names"]]
result <- datawizard::data_rename(result, pattern = old_names, replacement = new_names)
)[".new_names"]

name_map <- stats::setNames(new_names[[1]], old_names[[1]])
names(result) <- name_map[names(result)]
}
# remember values of first columns
variable <- result[[1]]["Variable"]
# number of observation, based on weights
if (!is.null(weights)) {

Check warning on line 198 in R/report_sample.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/report_sample.R,line=198,col=9,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
n_obs <- round(as.vector(stats::xtabs(data[[weights]] ~ data[[by]])))
} else {
n_obs <- as.vector(table(data[by]))
Expand Down Expand Up @@ -224,7 +227,7 @@
final$Total <- NULL
}
# define total N, based on weights
if (!is.null(weights)) {

Check warning on line 230 in R/report_sample.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/report_sample.R,line=230,col=9,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
total_n <- round(sum(as.vector(table(data[by]))) * mean(data[[weights]], na.rm = TRUE))
} else {
total_n <- sum(as.vector(table(data[by])))
Expand Down Expand Up @@ -265,7 +268,7 @@
ci = NULL,
ci_method = "wilson",
ci_correct = FALSE) {
if (!is.null(weights)) {

Check warning on line 271 in R/report_sample.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/report_sample.R,line=271,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
w <- x[[weights]]
columns <- setdiff(colnames(x), weights)
} else {
Expand Down Expand Up @@ -343,7 +346,7 @@
x <- as.factor(x)
}

if (!is.null(weights)) {

Check warning on line 349 in R/report_sample.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/report_sample.R,line=349,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
x[is.na(weights)] <- NA
weights[is.na(x)] <- NA
weights <- stats::na.omit(weights)
Expand All @@ -359,7 +362,7 @@
}

# CI for proportions?
if (!is.null(ci)) {

Check warning on line 365 in R/report_sample.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/report_sample.R,line=365,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
ci_low_high <- .ci_proportion(x, table_proportions, weights, ci, ci_method, ci_correct)
.summary <- sprintf(
"%.1f [%.1f, %.1f]",
Expand Down
Loading