tests/testthat/test-check_plink_results_unchanged.R

local_edition(3) 
results_file_name <- "example_results"


bed.file <- system.file(package="gwasurvivr",
                       "extdata",
                       "plink_example.bed")
covariate.file <- system.file(package="gwasurvivr", 
                              "extdata",
                              "simulated_pheno.txt")
covariate.file <- read.table(covariate.file,
                             sep=" ",
                             header=TRUE,
                             stringsAsFactors = FALSE)
covariate.file$SexFemale <- ifelse(covariate.file$sex=="female", 1L, 0L)
sample.ids <- covariate.file[covariate.file$group=="experimental",]$ID_2

plinkCoxSurv(bed.file=bed.file,
             covariate.file=covariate.file,
             id.column="ID_2",
             sample.ids=sample.ids,
             time.to.event="time",
             event="event",
             covariates=c("age", "SexFemale", "DrugTxYes"),
             inter.term=NULL,
             print.covs="only",
             out.file=results_file_name,
             chunk.size=50,
             maf.filter=0.005,
             exclude.snps = NULL,
             flip.dosage=TRUE,
             verbose=TRUE,
             clusterObj=NULL)
  
if(file.exists(paste0(results_file_name, ".coxph"))){
  results_file <- read.table(paste0(results_file_name, ".coxph"), 
                             sep="\t", 
                             header=TRUE, 
                             stringsAsFactors = FALSE)
} else {
  results_file <- NULL
}

test_that("check plink example results not changed", {
  expect_snapshot_output(results_file, cran = F)
})

if(file.exists(paste0(results_file_name, ".coxph"))){
  file.remove(paste0(results_file_name, ".coxph"))
}

if(file.exists(paste0(results_file_name, ".snps_removed"))){
  file.remove(paste0(results_file_name, ".snps_removed"))
}
suchestoncampbelllab/gwasurvivr documentation built on March 18, 2021, 5:50 p.m.