From f7abf05144072057cdd40c0b2e2e936131633480 Mon Sep 17 00:00:00 2001
From: Julian Sagebiel <julian.sagebiel@idiv.de>
Date: Sun, 23 Jun 2024 19:35:54 +0200
Subject: [PATCH] corrected tests for readdesign, solved small issues with path
 for csa vignette

---
 R/readdesign.R                   | 10 +++++-----
 man/readdesign.Rd                |  4 ++--
 tests/testthat/test-readdesign.R |  8 ++++----
 vignettes/csa-vignette.Rmd       |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/R/readdesign.R b/R/readdesign.R
index fb67522..6077351 100644
--- a/R/readdesign.R
+++ b/R/readdesign.R
@@ -5,7 +5,7 @@
 #'  Creates a dataframe with the design.
 #'
 #' @param design The path to a design file
-#' @param designtype Is it a design created with ngene or with spdesign. Ngene desings should be stored as the standard .ngd output. spdesign should be the spdesign object design$design
+#' @param designtype Is it a design created with ngene or with spdesign. Ngene desings should be stored as the standard .ngd output. spdesign should be the spdesign object stored as an RDS file. If designtype is not specified, I try to guess what it is. This is especially helpful if you want to carry out a simulation for both spdesign designs and ngene designs at the same time.
 #'
 #' @return a dataframe
 #' @export
@@ -27,14 +27,14 @@ readdesign <- function(design = designfile, designtype = NULL) {
 
 
     # Check if the string ends with ".ngd"
-    if (grepl("\\.ngd$", designfile)) {
+    if (grepl("\\.ngd$", design)) {
       # Code to execute if condition is true
       designtype = "ngene"
-      print("I guessed it is an ngene file")
+      message("I guessed it is an ngene file")
     } else {
       # Code to execute if condition is false
       designtype = "spdesign"
-      print("I assume it is a spdesign")
+      message("I assume it is a spdesign")
     }
 
   }
@@ -66,7 +66,7 @@ readdesign <- function(design = designfile, designtype = NULL) {
 
                    }
                    ,
-                   stop("Invalid value for design. Please provide either 'ngene' or 'spdesign'.")
+                   stop("Invalid value for design. Please provide either 'ngene' or 'spdesign', or do not use the argument 'designtype'.")
   )
 
 }
diff --git a/man/readdesign.Rd b/man/readdesign.Rd
index b74ed46..72011ee 100644
--- a/man/readdesign.Rd
+++ b/man/readdesign.Rd
@@ -4,12 +4,12 @@
 \alias{readdesign}
 \title{Creates a dataframe with the design.}
 \usage{
-readdesign(design = designfile, designtype = destype)
+readdesign(design = designfile, designtype = NULL)
 }
 \arguments{
 \item{design}{The path to a design file}
 
-\item{designtype}{Is it a design created with ngene or with spdesign. Ngene desings should be stored as the standard .ngd output. spdesign should be the spdesign object design$design}
+\item{designtype}{Is it a design created with ngene or with spdesign. Ngene desings should be stored as the standard .ngd output. spdesign should be the spdesign object stored as an RDS file. If designtype is not specified, I try to guess what it is. This is especially helpful if you want to carry out a simulation for both spdesign designs and ngene designs at the same time.}
 }
 \value{
 a dataframe
diff --git a/tests/testthat/test-readdesign.R b/tests/testthat/test-readdesign.R
index 97a3658..dcb699e 100644
--- a/tests/testthat/test-readdesign.R
+++ b/tests/testthat/test-readdesign.R
@@ -17,8 +17,8 @@ test_that("all is correct", {
 
 # test if autodetect ngd design
 
-test_that("all is correct", {
-  expect_no_error(readdesign(design = design_path))
+test_that("expect message of guess", {
+  expect_message(readdesign(design = design_path), "I guessed it is an ngene file")
 })
 
 
@@ -32,8 +32,8 @@ test_that("all is correct", {
 
 # Same Tests for spdesign, but detect automatically if it is spdesign
 
-test_that("all is correct", {
-  expect_no_error(readdesign(design = design_path))
+test_that("prints message for guessing", {
+  expect_message(readdesign(design = design_path), "I assume it is a spdesign")
 })
 
 
diff --git a/vignettes/csa-vignette.Rmd b/vignettes/csa-vignette.Rmd
index 2b23f1a..d5ebb3a 100644
--- a/vignettes/csa-vignette.Rmd
+++ b/vignettes/csa-vignette.Rmd
@@ -71,7 +71,7 @@ The simulation can be ran using spdesign or NGENE design files which will be con
 
 ```{r other}
 
-designpath<- system.file("extdata","CSA" ,package = "simulateDCE")
+designpath<- system.file("extdata","CSA", "linear" ,package = "simulateDCE")
 ## can also be specified using relative path eg. designpath<- "Projects/CSA/Designs/"
 
 #notes <- "This design consists of different heuristics. One group did not attend the methan attribute, another group only decided based on the payment"
-- 
GitLab