Skip to content

Commit 7440be2

Browse files
committed
v0.1.0
1 parent 87b980f commit 7440be2

File tree

9 files changed

+104
-4
lines changed

9 files changed

+104
-4
lines changed

DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: SuperPlotR
22
Title: Making SuperPlots in R
3-
Version: 0.0.8
3+
Version: 0.1.0
44
Authors@R:
55
person(given = "Stephen J",
66
family = "Royle",
@@ -16,7 +16,7 @@ Description: SuperPlots are a way to show experimental data in a way that
1616
License: MIT + file LICENSE
1717
Encoding: UTF-8
1818
Roxygen: list(markdown = TRUE)
19-
RoxygenNote: 7.3.2
19+
RoxygenNote: 7.3.3
2020
Depends:
2121
R (>= 2.10)
2222
Config/rcmdcheck/ignore-inconsequential-notes: true
@@ -31,5 +31,7 @@ URL: https://github.com/quantixed/SuperPlotR, https://quantixed.github.io/SuperP
3131
BugReports: https://github.com/quantixed/SuperPlotR/issues
3232
Suggests:
3333
knitr,
34-
rmarkdown
34+
rmarkdown,
35+
testthat (>= 3.0.0)
3536
VignetteBuilder: knitr
37+
Config/testthat/edition: 3

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# SuperPlotR (development version)
1+
# SuperPlotR
2+
3+
## SuperPlotR 0.1.0
4+
5+
* Test structure added. Bumping to 0.1.0 to reflect this change.
26

37
## SuperPlotR 0.0.8
48

tests/testthat.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library(testthat)
2+
library(SuperPlotR)
3+
4+
test_check("SuperPlotR")
5+
# This file is part of the standard setup for testthat.
6+
# It is recommended that you do not modify it.
7+
#
8+
# Where should you do additional test configuration?
9+
# Learn more about the roles of various files in:
10+
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
11+
# * https://testthat.r-lib.org/articles/special-files.html
12+
13+
library(testthat)
14+
library(SuperPlotR)
15+
16+
test_check("SuperPlotR")

tests/testthat/test-add-sp-bars.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
test_that("add_sp_bars adds errorbar and crossbar layers", {
2+
df <- data.frame(group = rep(c("A","B"), each = 5),
3+
value = c(rep(1,5), rep(2,5)),
4+
repl = rep(1:5, 2))
5+
p0 <- ggplot2::ggplot(df, ggplot2::aes(x = group, y = value))
6+
p <- add_sp_bars(p0, bars = "mean_sem", df = df, cond = "group", rep_summary = "value")
7+
expect_s3_class(p, "ggplot")
8+
layer_classes <- vapply(p$layers, function(l) class(l$geom)[1], character(1))
9+
expect_true(any(grepl("GeomErrorbar|GeomCrossbar", layer_classes)))
10+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
test_that("get_sp_colours returns correct length and repeats custom vector", {
2+
cols <- get_sp_colours(3, "tol_bright")
3+
expect_type(cols, "character")
4+
expect_length(cols, 3)
5+
6+
# custom vector of colours is repeated to length n
7+
custom <- c("#FF0000", "green")
8+
cols2 <- get_sp_colours(5, custom)
9+
expect_length(cols2, 5)
10+
expect_equal(cols2[1:2], custom)
11+
})
12+
13+
test_that("get_sp_colours errors on invalid scheme", {
14+
expect_error(get_sp_colours(2, "not_a_palette"))
15+
})

tests/testthat/test-get-sp-stats.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
test_that("get_sp_stats prints sensible messages for edge cases and tests", {
2+
df1 <- data.frame(condition = rep("A", 3), rep_mean = c(1,2,3))
3+
expect_output(get_sp_stats(df1, "rep_mean", "condition", NULL, 1, 1, "para_unpaired"),
4+
"Only one condition")
5+
6+
df2 <- data.frame(condition = rep(c("X","Y"), each = 2), rep_mean = c(1,2,3,4))
7+
# nrepl < 3 should report less than three replicates
8+
expect_output(get_sp_stats(df2, "rep_mean", "condition", NULL, 2, 2, "para_unpaired"),
9+
"Less than three replicates")
10+
11+
# a valid two-group t-test path emits 'Performing t-test'
12+
df3 <- data.frame(condition = rep(c("X","Y"), each = 3),
13+
rep_mean = c(1,2,3, 4,5,6))
14+
expect_output(get_sp_stats(df3, "rep_mean", "condition", NULL, 2, 3, "para_unpaired"),
15+
"Performing t-test")
16+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
test_that("representative returns expected structure and ranks", {
2+
df <- data.frame(group = rep("G", 5),
3+
repl = rep(1, 5),
4+
value = c(1,2,3,4,5))
5+
res <- representative(df, meas = "value", cond = "group", repl = "repl")
6+
expect_true(is.data.frame(res))
7+
expect_true("rank" %in% names(res))
8+
expect_true(all(res$rank >= 1))
9+
10+
# test with a label column
11+
df2 <- df
12+
df2$label <- letters[1:5]
13+
res2 <- representative(df2, meas = "value", cond = "group", repl = "repl", label = "label")
14+
expect_true(is.data.frame(res2))
15+
expect_true("label" %in% names(res2))
16+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
test_that("superplot returns a ggplot and contains expected data rows", {
2+
set.seed(42)
3+
df <- data.frame(
4+
condition = rep(c("C1", "C2"), each = 4),
5+
replicate = rep(1:4, times = 2),
6+
value = rnorm(8)
7+
)
8+
p <- superplot(df, meas = "value", cond = "condition", repl = "replicate")
9+
expect_s3_class(p, "ggplot")
10+
11+
gb <- ggplot2::ggplot_build(p)
12+
# ensure at least one layer contains data rows
13+
total_rows <- sum(vapply(gb$data, nrow, integer(1)))
14+
expect_true(total_rows >= 8)
15+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test_that("vdiffr visual test for a small superplot (skipped if vdiffr missing)", {
2+
testthat::skip_if_not_installed("vdiffr")
3+
data(lord_jcb, package = "SuperPlotR")
4+
p <- superplot(lord_jcb, meas = "Speed", cond = "Treatment", repl = "Replicate")
5+
vdiffr::expect_doppelganger("superplot-lord_jcb", p)
6+
})

0 commit comments

Comments
 (0)