tests/testthat/test-ggseqeplot.R

# Example data come from TraMineR
library(TraMineR)
# biofam data set
data(biofam)
# We use only a sample of 300 cases
set.seed(10)
biofam <- biofam[sample(nrow(biofam), 300), ]
biofam.lab <- c(
  "Parent", "Left", "Married", "Left+Marr",
  "Child", "Left+Child", "Left+Marr+Child", "Divorced"
)
biofam.seq <- seqdef(biofam, 10:25, labels = biofam.lab, weights = biofam$wp00tbgs)
biofam2.seq <- seqdef(biofam, 10:25, labels = biofam.lab)
group <- as.integer(biofam$sex)

group_labelled <- haven::labelled(as.integer(biofam$sex),
                                  labels = c("Male" = 1, "Female" = 2))



data(ex1)
ex1.seq <- seqdef(ex1, 1:13, weights = ex1$weights)


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test_that("arguments are specified correctly (length, type, ...)", {
  expect_error(ggseqeplot(biofam))
  expect_error(ggseqeplot(biofam.seq, group = biofam$birthyr))
  expect_error(ggseqeplot(biofam.seq, group = biofam$sex, linecolor = "green"))
  expect_error(ggseqeplot(biofam.seq, group = group[1:100]))
  expect_error(ggseqeplot(biofam.seq, weighted = group))
})

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test_that("haven_labelled group is converted to factor with warning", {
  expect_warning(ggseqeplot(biofam.seq,
                             group = group_labelled))
})

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test_that("check if output of ggseqtrplot is ggplot", {
  expect_s3_class(ggseqeplot(biofam.seq), "ggplot")
  expect_s3_class(ggseqeplot(biofam2.seq), "ggplot")
  expect_s3_class(ggseqeplot(ex1.seq), "ggplot")
  expect_s3_class(ggseqeplot(biofam.seq, group = biofam$sex,
                             gr.linetype = TRUE), "ggplot")
})

Try the ggseqplot package in your browser

Any scripts or data that you put into this service are public.

ggseqplot documentation built on Nov. 15, 2025, 5:06 p.m.