Skip to content

Commit

Permalink
more linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Feb 9, 2024
1 parent cb97af7 commit 727dbe7
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 134 deletions.
15 changes: 12 additions & 3 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
linters: all_linters(
assignment_linter = NULL,
commas_linter(allow_trailing = TRUE),
commas_linter = NULL,
consecutive_assertion_linter = NULL,
duplicate_argument_linter(except = c("mutate", "transmute", "c")),
expect_identical_linter = NULL,
expect_null_linter = NULL,
expect_true_false_linter = NULL,
function_argument_linter = NULL,
implicit_integer_linter = NULL,
infix_spaces_linter(exclude_operators = c("/", "*")),
keyword_quote_linter = NULL,
line_length_linter(120L),
missing_argument_linter(except = c("alist", "quote", "switch", "pairlist2")),
missing_argument_linter(except = c("alist", "quote", "switch", "pairlist2", "lapply")),
nested_ifelse_linter = NULL,
nonportable_path_linter = NULL,
numeric_leading_zero_linter = NULL,
object_length_linter = NULL,
object_name_linter(
Expand All @@ -16,14 +22,17 @@ linters: all_linters(
misc = "^(F_x|x_1_hat,x_n_hat|R_inv|Amat|Aind)$",
CamelCase = "^(RankCorr.*|.*Geom.*|.*Stat.*|Scale.*|Position.*|K|Mode.*|.*Pr.*|.*linearGradient.*|\\.Deprecated.*)$",
dot.case = "^(na\\.rm|na\\.translate|na\\.value|lower\\.tail|log\\.p|width\\.cutoff)$",
bandwidth = "^(bandwidth_.*)$"
bandwidth = "^(bandwidth_.*)$",
breaks = "^breaks_.*$"
)
),
object_overwrite_linter(
allow_names = c("dist", "data", "layout", "pdf", "q")
),
object_usage_linter = NULL,
quotes_linter = NULL,
scalar_in_linter = NULL,
todo_comment_linter = NULL,
undesirable_function_linter(modify_defaults(
defaults = all_undesirable_functions,
library = NULL,
Expand Down
4 changes: 1 addition & 3 deletions R/geom_dotsinterval.R
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ GeomDotsinterval = ggproto("GeomDotsinterval", GeomSlabinterval,
aes_docs
},

hidden_aes = union(c(
"thickness"
), GeomSlabinterval$hidden_aes),
hidden_aes = union("thickness", GeomSlabinterval$hidden_aes),

default_aes = defaults(aes(
family = "",
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/tests.html
# * https://testthat.r-lib.org/reference/test_package.html#special-files
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(ggdist)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test.binning_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ test_that("bin nudging works", {
NULL
)
expect_equal(
nudge_bins(c(1), width = 1),
c(1)
nudge_bins(1, width = 1),
1
)
expect_equal(
nudge_bins(c(1,2), width = 1),
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test.lkj_marginal.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ test_that("lkjcorr_marginal throws an error for invalid K", {
test_that("marginalize_lkjcorr works", {
ref = as.data.frame(tibble(
coef = c("a", "b"),
prior = c("lkjcorr(3)", "lkjcorr(3)" ),
prior = c("lkjcorr(3)", "lkjcorr(3)"),
.dist = c("lkjcorr_marginal", "lkjcorr_marginal"),
.args = list(list(2, 3), list(4, 3)),
.dist_obj = dist_wrap(dist = "lkjcorr_marginal", c(2, 4), c(3, 3), package = "ggdist"),
.dist_obj = dist_wrap(dist = "lkjcorr_marginal", c(2, 4), c(3, 3), package = "ggdist")
))

expect_equal(
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test.rd_lineribbon.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ test_that("lineribbon aesthetic documention generator works", {

test_that("shortcut stat documentation generator works", {

stat_output = paste0(rd_lineribbon_shortcut_stat("lineribbon", chart_type = "multiple-ribbon", from_name = "slabinterval"), collapse = "\n")
stat_output = paste0(
rd_lineribbon_shortcut_stat("lineribbon", chart_type = "multiple-ribbon", from_name = "slabinterval"),
collapse = "\n"
)
expect_match(stat_output, "@title Multiple-ribbon plot (shortcut stat)", fixed = TRUE)
expect_match(stat_output, ".width = c(0.5, 0.8, 0.95)", fixed = TRUE)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test.scale_.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test_that("direct scale setting works", {
slab_linetype = "dotted",
slab_alpha = .5
)
)
)
})

test_that("mapping custom aesthetics works", {
Expand Down
18 changes: 15 additions & 3 deletions tests/testthat/test.smooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,30 @@ test_that("smooth_discrete works", {
x = rep(1:4, times = 4:1)

ld = layer_data(ggplot() + geom_dots(aes(x), smooth = "discrete"))
ref_x = c(0.760112695656659, 0.920256356040445, 1.08040001642423, 1.24054367680802, 1.78654853188863, 2.00007341240034, 2.21359829291206, 2.83977362126489, 3.16006094203247, 3.99967181376766)
ref_x = c(
0.760112695656659, 0.920256356040445, 1.08040001642423, 1.24054367680802,
1.78654853188863, 2.00007341240034, 2.21359829291206, 2.83977362126489,
3.16006094203247, 3.99967181376766
)
expect_equal(ld$x, ref_x, tolerance = 0.001)

ld = layer_data(ggplot() + geom_dots(aes(x), smooth = smooth_discrete(kernel = "ep")))
ref_x = c(0.816364320617873, 0.944625373470495, 1.05539072151476, 1.18366670884155, 1.84144365484769, 2.00000507797274, 2.15857922335003, 2.88568947241406, 3.11432520840337, 3.99999280566278)
ref_x = c(
0.816364320617873, 0.944625373470495, 1.05539072151476, 1.18366670884155,
1.84144365484769, 2.00000507797274, 2.15857922335003, 2.88568947241406,
3.11432520840337, 3.99999280566278
)
expect_equal(ld$x, ref_x, tolerance = 0.001)
})

test_that("smooth_bounded works", {
x = 1:10

ld = layer_data(ggplot() + geom_dots(aes(x), smooth = "bounded"))
ref_x = c(0.997794316080475, 1.99639357461413, 2.99631978598422, 3.99740164666058, 4.99908084276668, 6.00091915723332, 7.00259835333942, 8.00368021401578, 9.00360642538587, 10.0022056839195)
ref_x = c(
0.997794316080475, 1.99639357461413, 2.99631978598422, 3.99740164666058,
4.99908084276668, 6.00091915723332, 7.00259835333942, 8.00368021401578,
9.00360642538587, 10.0022056839195
)
expect_equal(ld$x, ref_x, tolerance = 0.001)
})
2 changes: 1 addition & 1 deletion tests/testthat/test.stat_cdfinterval.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_that("dodged ccdf barplots work", {
skip_if_no_vdiffr()


df = data.frame(y = 1:5, x = "a", g = c("g1")) %>%
df = data.frame(y = 1:5, x = "a", g = "g1") %>%
rbind(data.frame(y = rep(1:5, each = 3) + 1:3, x = "b", g = c("g1", "g2", "g3")))

p = ggplot(df, aes(x = x, y = y))
Expand Down
14 changes: 12 additions & 2 deletions tests/testthat/test.stat_sample_slabinterval.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,22 @@ test_that("scale transformation works on halfeye", {
scale_x_log10(breaks = 10^seq(-1,1))

vdiffr::expect_doppelganger("halfeyeh log scale tri",
p_log + stat_halfeye(point_interval = mode_hdci, n = 20, density = density_unbounded(kernel = "tri"), .width = .5) +
p_log +
stat_halfeye(
point_interval = mode_hdci, n = 20,
density = density_unbounded(kernel = "tri"),
.width = .5
) +
geom_point(data = data.frame(x = 10^c(-1, 1)))
)

vdiffr::expect_doppelganger("halfeyeh log scale tri no trim",
p_log + stat_halfeye(point_interval = mode_hdci, n = 20, density = density_unbounded(kernel = "tri"), trim = FALSE, .width = .5) +
p_log +
stat_halfeye(
point_interval = mode_hdci, n = 20,
density = density_unbounded(kernel = "tri"), trim = FALSE,
.width = .5
) +
geom_point(data = data.frame(x = 10^c(-1, 1)))
)

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test.student_t.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ test_that("student_t functions work", {
set.seed(1234)
expect_equal(rstudent_t(10, df, median, scale), r)
})

3 changes: 2 additions & 1 deletion tests/testthat/test.theme_ggdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ test_that("theme helper functions work", {
p = data.frame(
x = 1:2,
y = 0,
g = c("aaa","bbb")
g = c("aaa","bbb"),
stringsAsFactors = FALSE
) %>%
ggplot(aes(x, y)) +
geom_point() +
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test.weighted_ecdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ test_that("weighted_ecdf works", {
})

test_that("quantile(<weighted_ecdf>) works", {
expect_equal(quantile(weighted_ecdf(c(1, 2, 2, 3), 1:4), ppoints(10)), weighted_quantile(c(1, 2, 2, 3), weights = 1:4, ppoints(10)))
expect_equal(
quantile(weighted_ecdf(c(1, 2, 2, 3), 1:4), ppoints(10)),
weighted_quantile(c(1, 2, 2, 3), weights = 1:4, ppoints(10))
)
})
20 changes: 16 additions & 4 deletions tests/testthat/test.weighted_hist.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,22 @@ test_that("align functions work", {
x = c(1,2,3,4,5,6)
breaks = c(0.25, 2.25, 4.25, 6.25)

expect_equal(weighted_hist(x, breaks = breaks, align = 0.25), weighted_hist(x, breaks = breaks - 0.25))
expect_equal(weighted_hist(x, breaks = breaks, align = align_none()), weighted_hist(x, breaks = breaks))
expect_equal(weighted_hist(x, breaks = breaks, align = align_center(at = 2)), weighted_hist(x, breaks = breaks + 0.75))
expect_equal(weighted_hist(x, breaks = breaks, align = align_boundary(at = 2)), weighted_hist(x, breaks = breaks - 0.25))
expect_equal(
weighted_hist(x, breaks = breaks, align = 0.25),
weighted_hist(x, breaks = breaks - 0.25)
)
expect_equal(
weighted_hist(x, breaks = breaks, align = align_none()),
weighted_hist(x, breaks = breaks)
)
expect_equal(
weighted_hist(x, breaks = breaks, align = align_center(at = 2)),
weighted_hist(x, breaks = breaks + 0.75)
)
expect_equal(
weighted_hist(x, breaks = breaks, align = align_boundary(at = 2)),
weighted_hist(x, breaks = breaks - 0.25)
)
})


Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test.weighted_quantile.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ test_that("weighted_quantile is equivalent to quantile on non-weighted samples",

test_that("weighted_quantile is equivalent to quantile on weighted samples", {
x = c(1,1,1,1,2,2,2,3,3,4)
xw = c(1:4)
w = c(4:1)
xw = 1:4
w = 4:1

p = ppoints(20, a = 1)
for (type in 1:9) {
Expand Down Expand Up @@ -48,4 +48,3 @@ test_that("0- and 1-length vectors work", {

expect_equal(weighted_quantile(numeric(), c(0, 0.5, 1, NA), names = FALSE), c(NA_real_, NA_real_, NA_real_, NA_real_))
})

Loading

0 comments on commit 727dbe7

Please sign in to comment.