diff --git a/DESCRIPTION b/DESCRIPTION index b490d8fb..0385902d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: NMdata Type: Package Title: Preparation, Checking and Post-Processing Data for PK/PD Modeling -Version: 0.1.8.941 +Version: 0.1.8.942 Authors@R: c(person(given="Philip", family="Delff",email = "philip@delff.dk",role = c("aut", "cre")), person("Brian", "Reilly", email = "reilly.brian.m@gmail.com",role = c("ctb")), diff --git a/R/addOmegaCorr.R b/R/addOmegaCorr.R index c4bfb6bb..c0976b7a 100644 --- a/R/addOmegaCorr.R +++ b/R/addOmegaCorr.R @@ -1,5 +1,4 @@ ##' add Omega correlations to a parameter table - ##' @param pars A parameter table, like returned by `NMreadExt()`. ##' @param by The name of a column, as a string. Calculate the ##' correlations within a grouping variable? This will often be a @@ -42,11 +41,30 @@ addOmegaCorr <- function(pars,by=NULL,as.fun,col.value="value"){ res.list <- lapply( pars.list, function(x){ - Sigma <- dt2mat(x[par.type=="OMEGA"],col.value=col.value) - mat.cor <- suppressWarnings(cov2cor(Sigma)) - dt.cor <- mat2dt(mat.cor,triangle="all") + + x.omega <- x[par.type=="OMEGA"] + dt.cor <- NULL + if(nrow(x.omega)){ + Sigma <- dt2mat(x.omega,col.value=col.value) + mat.cor <- suppressWarnings(cov2cor(Sigma)) + dt.cor.1 <- mat2dt(mat.cor,triangle="all",as.fun="data.table")[,par.type:="OMEGA"] + ##x <- mergeCheck(x,dt.cor[,.(par.type="OMEGA",i,j,corr=get(col.value))],by=cc(par.type,i,j),all.x=TRUE,quiet=TRUE) + dt.cor <- rbind(dt.cor,dt.cor.1) + } - x <- mergeCheck(x,dt.cor[,.(par.type="OMEGA",i,j,corr=get(col.value))],by=cc(par.type,i,j),all.x=TRUE) + x.sigma <- x[par.type=="SIGMA"] + if(nrow(x.sigma)){ + Sigma <- dt2mat(x.sigma,col.value=col.value) + mat.cor <- suppressWarnings(cov2cor(Sigma)) + dt.cor.1 <- mat2dt(mat.cor,triangle="all",as.fun="data.table")[,par.type:="SIGMA"] + ## x <- mergeCheck(x,dt.cor[,.(par.type="SIGMA",i,j,corr=get(col.value))],by=cc(par.type,i,j),all.x=TRUE,quiet=TRUE) + dt.cor <- rbind(dt.cor,dt.cor.1) + } + if(!is.null(dt.cor)){ + dt.cor <- dt.cor[,.(par.type,i,j,corr=get(col.value))] + dt.cor[is.nan(corr),corr:=0] + x <- mergeCheck(x,dt.cor,by=cc(par.type,i,j),all.x=TRUE,quiet=TRUE) + } x }) diff --git a/man/NMreadSection.Rd b/man/NMreadSection.Rd index be38cc48..8ff211cb 100644 --- a/man/NMreadSection.Rd +++ b/man/NMreadSection.Rd @@ -94,9 +94,9 @@ suitable for the results part too. } \section{Functions}{ \itemize{ -\item \code{NMgetSection()}: Deprecated function name. Use NMreadSection. - +\item \code{NMgetSection}: Deprecated function name. Use NMreadSection. }} + \examples{ NMreadSection(system.file("examples/nonmem/xgxr001.lst", package="NMdata"),section="DATA") diff --git a/tests/testthat/testReference/NMcheckData_22.rds b/tests/testthat/testReference/NMcheckData_22.rds new file mode 100644 index 00000000..c5ff9a55 Binary files /dev/null and b/tests/testthat/testReference/NMcheckData_22.rds differ diff --git a/tests/testthat/testReference/NMwriteSection_08.rds b/tests/testthat/testReference/NMwriteSection_08.rds new file mode 100644 index 00000000..a051a46b Binary files /dev/null and b/tests/testthat/testReference/NMwriteSection_08.rds differ diff --git a/tests/testthat/testReference/addOmegaCorr_01.rds b/tests/testthat/testReference/addOmegaCorr_01.rds new file mode 100644 index 00000000..277b7f4f Binary files /dev/null and b/tests/testthat/testReference/addOmegaCorr_01.rds differ diff --git a/tests/testthat/testReference/compareCols_06.rds b/tests/testthat/testReference/compareCols_06.rds new file mode 100644 index 00000000..548bfd57 Binary files /dev/null and b/tests/testthat/testReference/compareCols_06.rds differ diff --git a/tests/testthat/test_addOmegaCorr.R b/tests/testthat/test_addOmegaCorr.R new file mode 100644 index 00000000..9372400f --- /dev/null +++ b/tests/testthat/test_addOmegaCorr.R @@ -0,0 +1,16 @@ +library(data.table) +context("addOmegaCorr") + +test_that("basic",{ + + fileRef <- "testReference/addOmegaCorr_01.rds" + file.mod <- "testData/nonmem/xgxr022.mod" + + ext <- NMreadExt(file.mod) + + res1 <- addOmegaCorr(ext) + + res1 + expect_equal_to_reference(res1,fileRef) + +})