From 6b91053da747a965a952e2ebfda374785fbf569c Mon Sep 17 00:00:00 2001 From: Robert Rostu Studtrucker Date: Wed, 4 Sep 2024 10:54:49 +0200 Subject: [PATCH] add testing script; fixed problem with parameter nesting for rmaMvModel --- NAMESPACE | 1 + R/rmaMVModel.R | 18 +++++++++++------- R/testFunctions.R | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 R/testFunctions.R diff --git a/NAMESPACE b/NAMESPACE index af5687c..4e2f402 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,3 +26,4 @@ export(checkIntegrity) export(checkData) export(checkParameter) export(createData) +export(testListParameter) diff --git a/R/rmaMVModel.R b/R/rmaMVModel.R index 2610a67..e46a36e 100644 --- a/R/rmaMVModel.R +++ b/R/rmaMVModel.R @@ -29,7 +29,11 @@ rmaMVModel <- function(yi,vi,measure,d,pred1=NULL,pred2=NULL,nesting=NULL) { #load the in variable d defined dataset from the package dat <- d - #checkParameter(dat,c(yi,vi)) + if(nesting != NULL){ + nesting <- fromJSON(nesting) + } + summary(dat) + checkParameter(dat,c(yi,vi)) pred1<-unlist(pred1) pred2<-unlist(pred2) @@ -38,13 +42,13 @@ rmaMVModel <- function(yi,vi,measure,d,pred1=NULL,pred2=NULL,nesting=NULL) { if(is.null(nesting)){ nest<-list(~1 | outcome_ID ,~1 | sample_ID ,~1 | report_ID) }else{ - nest<-list() - i=1 - for(p in nesting){ - nest[i] <-paste("~1 |", p) - i=i+1 + # Initialize an empty list to store the formulas + nest <- list() + # Iterate over the parsed JSON array and create formulas + for (i in seq_along(nesting)) { + # Create a formula and assign it to the nest list + nest[[i]] <- as.formula(paste("~1 |", nesting[[i]])) } - nest<-lapply(nest, as.formula) } # there is no moderator defined if( is.null(pred1) && is.null(pred2)){ diff --git a/R/testFunctions.R b/R/testFunctions.R new file mode 100644 index 0000000..1549e80 --- /dev/null +++ b/R/testFunctions.R @@ -0,0 +1,22 @@ +library(jsonlite) + +testListParameter <- function(nesting = NULL) { + # Parse the JSON input string + nesting <- fromJSON(nesting) + + # Initialize an empty list to store the formulas + nest <- list() + + # Iterate over the parsed JSON array and create formulas + for (i in seq_along(nesting)) { + # Create a formula and assign it to the nest list + nest[[i]] <- as.formula(paste("~1 |", nesting[[i]])) + } + + # Print the resulting nest list + print(nest) + + # Original nest2 for comparison + nest2 <- list(~1 | outcome_ID, ~1 | sample_ID, ~1 | report_ID) + print(nest2) +}