Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 13, 2024
1 parent 07e7df2 commit 06146e5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 48 deletions.
43 changes: 21 additions & 22 deletions R/data_tabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,28 @@ data_tabulate.default <- function(x,
} else {
freq_table <- tryCatch(table(x), error = function(e) NULL)
}
} else if (include_na) {
# weighted frequency table, including NA
freq_table <- tryCatch(
stats::xtabs(
weights ~ x,
data = data.frame(weights = weights, x = addNA(x)),
na.action = stats::na.pass,
addNA = TRUE
),
error = function(e) NULL
)
} else {
# weighted frequency table
if (include_na) {
freq_table <- tryCatch(
stats::xtabs(
weights ~ x,
data = data.frame(weights = weights, x = addNA(x)),
na.action = stats::na.pass,
addNA = TRUE
),
error = function(e) NULL
)
} else {
freq_table <- tryCatch(
stats::xtabs(
weights ~ x,
data = data.frame(weights = weights, x = x),
na.action = stats::na.omit,
addNA = FALSE
),
error = function(e) NULL
)
}
# weighted frequency table, excluding NA
freq_table <- tryCatch(
stats::xtabs(
weights ~ x,
data = data.frame(weights = weights, x = x),
na.action = stats::na.omit,
addNA = FALSE
),
error = function(e) NULL
)
}

if (is.null(freq_table)) {
Expand Down
51 changes: 25 additions & 26 deletions R/data_xtabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,28 @@
} else {
x_table <- tryCatch(table(x, by), error = function(e) NULL)
}
} else if (include_na) {
# weighted frequency table, including NA
x_table <- tryCatch(
stats::xtabs(
weights ~ x + by,
data = data.frame(weights = weights, x = addNA(x), by = addNA(by)),
na.action = stats::na.pass,
addNA = TRUE
),
error = function(e) NULL
)
} else {
# weighted frequency table
if (include_na) {
x_table <- tryCatch(
stats::xtabs(
weights ~ x + by,
data = data.frame(weights = weights, x = addNA(x), by = addNA(by)),
na.action = stats::na.pass,
addNA = TRUE
),
error = function(e) NULL
)
} else {
x_table <- tryCatch(
stats::xtabs(
weights ~ x + by,
data = data.frame(weights = weights, x = x, by = by),
na.action = stats::na.omit,
addNA = FALSE
),
error = function(e) NULL
)
}
# weighted frequency table, excluding NA
x_table <- tryCatch(
stats::xtabs(
weights ~ x + by,
data = data.frame(weights = weights, x = x, by = by),
na.action = stats::na.omit,
addNA = FALSE
),
error = function(e) NULL
)
}

if (is.null(x_table)) {
Expand Down Expand Up @@ -152,19 +151,19 @@ format.dw_data_xtabulate <- function(x, format = "text", digits = 1, big_mark =
ftab$Total <- gsub("\\.00$", "", as.character(total_column))
# for text format, insert "empty row" before last total row
if (identical(format, "text") || identical(format, "markdown")) {
sub <- as.data.frame(t(data.frame(
empty_row <- as.data.frame(t(data.frame(
rep("", ncol(ftab)),
c("Total", as.character(total_row)),
stringsAsFactors = FALSE
)))
} else {
sub <- as.data.frame(t(data.frame(
empty_row <- as.data.frame(t(data.frame(
c("Total", as.character(total_row)),
stringsAsFactors = FALSE

Check warning on line 162 in R/data_xtabulate.R

View check run for this annotation

Codecov / codecov/patch

R/data_xtabulate.R#L160-L162

Added lines #L160 - L162 were not covered by tests
)))
}
colnames(sub) <- colnames(ftab)
ftab <- rbind(ftab, sub)
colnames(empty_row) <- colnames(ftab)
ftab <- rbind(ftab, empty_row)
ftab[nrow(ftab), ] <- gsub("\\.00$", "", ftab[nrow(ftab), ])

# insert big marks?
Expand Down

0 comments on commit 06146e5

Please sign in to comment.