Skip to content

Commit b2e5f7b

Browse files
committed
fix lints and test
1 parent 362f362 commit b2e5f7b

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

.lintr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ linters: linters_with_defaults(
66
cyclocomp_linter = NULL,
77
indentation_linter = indentation_linter(4),
88
object_length_linter = object_length_linter(40)
9+
return_linter = NULL
910
)
1011
exclusions: list(
1112
"design/tests",

R/populationHR.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ populationHR <- function(
8080
quantiles <- stats::quantile(x, probs = quantiles)
8181
c(mean = mean(x), median = median(x), quantiles)
8282
}) |>
83-
t() |> data.frame()
83+
t() |>
84+
data.frame()
8485

8586
list(summary = tidy_res, estimates)
8687
}

tests/testthat/test-populationHR.R

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,21 @@ test_that("populationHR works as expected for default parameters", {
2727
)
2828

2929
# Summary calculations are match expectations
30-
summary_stats <- apply(result[[2]], 1, function(x) c(mean(x), quantile(x, c(0.5, 0.025, 0.975))))
30+
summary_stats <- apply(result[[2]], 1, function(x) c(mean(x), quantile(x, c(0.5, 0.025, 0.975)))) |>
31+
t() |>
32+
as.data.frame()
3133
expect_equal(
32-
unname(t(summary_stats)),
34+
unname(summary_stats),
3335
unname(result[[1]])
3436
)
3537
})
3638

3739
test_that("populationHR fails for bad input", {
3840
mp <- test_data_1$jsamples
3941
expect_error(populationHR(object = mp@data), "inherit from class")
40-
expect_error(populationHR(object = mp, HR_formula = "arm"), "formula")
42+
expect_error(populationHR(object = mp, hr_formula = "arm"), "formula")
4143
expect_error(populationHR(object = mp, baseline = ~arm), "time term")
42-
expect_error(populationHR(object = mp, HR_formula = ~XX), "All variables")
44+
expect_error(populationHR(object = mp, hr_formula = ~XX), "All variables")
4345
expect_error(populationHR(object = mp, quantiles = c(-0.3, NA, 2)), "quantiles")
4446
})
4547

@@ -51,7 +53,7 @@ test_that("populationHR works as expected for alternative specfications", {
5153
result_arm_cont <- populationHR(
5254
object = mp,
5355
baseline = ~splines::ns(time, df = 5),
54-
HR_formula = ~arm + cov_cont,
56+
hr_formula = ~arm + cov_cont,
5557
quantiles = c(0.05, 0.95)
5658
)
5759

@@ -64,9 +66,12 @@ test_that("populationHR works as expected for alternative specfications", {
6466

6567

6668
### Summary calculations match expectations
67-
summary_stats <- apply(result_arm_cont[[2]], 1, function(x) c(mean(x), quantile(x, c(0.5, 0.05, 0.95))))
69+
summary_stats <- apply(result_arm_cont[[2]], 1, function(x) c(mean(x), quantile(x, c(0.5, 0.05, 0.95)))) |>
70+
t() |>
71+
as.data.frame()
72+
6873
expect_equal(
69-
unname(t(summary_stats)),
74+
unname(summary_stats),
7075
unname(result_arm_cont[[1]])
7176
)
7277

@@ -76,7 +81,7 @@ test_that("populationHR works as expected for alternative specfications", {
7681
result_arm <- populationHR(
7782
object = mp,
7883
baseline = ~splines::ns(time, df = 10),
79-
HR_formula = ~arm,
84+
hr_formula = ~arm,
8085
quantiles = c(0.05, 0.95)
8186
)
8287

@@ -88,9 +93,11 @@ test_that("populationHR works as expected for alternative specfications", {
8893
)
8994

9095
# Summary calculations match expectations
91-
summary_stats <- apply(result_arm[[2]], 1, function(x) c(mean(x), quantile(x, c(0.5, 0.05, 0.95))))
96+
summary_stats <- apply(result_arm[[2]], 1, function(x) c(mean(x), quantile(x, c(0.5, 0.05, 0.95)))) |>
97+
t() |>
98+
as.data.frame()
9299
expect_equal(
93-
unname(t(summary_stats)),
94-
unname(result_arm[[1]])
100+
unname(summary_stats),
101+
unname(result[[1]])
95102
)
96103
})

0 commit comments

Comments
 (0)