tests/testthat/test-dssCoxph.R

test_that("dssCoxph works", {
  datashield.aggregate(opals["server1"], as.symbol('partialData("cancer", NULL, NULL, "survival")'))
  new.df <- 'sex = c(1, 2), age = rep(mean(cancer$age, na.rm = TRUE), 2), ph.ecog = c(1, 1)'
  cox.res <- dssCoxph(formula = survival::Surv(time, status) ~ age + sex + ph.ecog, data = 'cancer', new.dataframe = new.df, async = FALSE, datasources = opals["server1"])
  x <-  unclass(summary(cox.res$server1$model))
  expect_true(all(abs(x$loglik - c(-744.4805, -729.2301)) < 1e-03))
  #try(file.remove('survfit_now.png'))
  png('survfit_now.png')

  plot(cox.res$server1$fit, conf.int = TRUE, col = c('blue', 'red'))
  dev.off()
  this_file <- file('survfit_now.png', 'rb')
  mod <- file('survfit_model.png', 'rb')
  this_one <- readBin(this_file, 'raw', n = 1000)
  correct_one <- readBin(mod, 'raw', n = 1000)
  close(this_file)
  close(mod)
  expect_identical(this_one, correct_one)
  try(file.remove('survfit_now.png'))
})
sib-swiss/dsSwissKnifeClient documentation built on July 16, 2025, 6:25 p.m.