diff --git a/DESCRIPTION b/DESCRIPTION index 767127bb..0ca44983 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.7.903 +Version: 0.1.7.904 Authors@R: c(person(given="Philip", family="Delff", email = "philip@delff.dk", diff --git a/NEWS.md b/NEWS.md index 46830a0e..f1ecf469 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,9 @@ * NMscanMultiple would sometimes print a bit of a messy overview of the results. That has been fixed without implications on the results returned. + +* dt2mat() now returns actual matrix objects. This provides + compatibility with the simpar package. # NMdata 0.1.7 diff --git a/R/dt2mat.R b/R/dt2mat.R index b213e781..330313a6 100644 --- a/R/dt2mat.R +++ b/R/dt2mat.R @@ -8,7 +8,10 @@ ##' @param dt.subset Specifies whether pars contains only a lower or ##' upper triangle of an assumed symmetric matrix (most often the ##' case for variance-covariance matrices), or it contains the -##' full matrix. +##' full matrix. `dt.subset="unique"` (default) means that `pars` only +##' contains either upper or lower diagonal matrix (including +##' diagonal), `dt.subset="all"` means `pars` contains both upper +##' and lower triangles. See details. ##' @param max.i By default, the maximum row number is derived as he ##' maximum value in the `i` column. If more (empty ones) are ##' needed, specify the maximum row number with `max.i`. This can @@ -21,9 +24,9 @@ ##' output from `NMreadExt()`. ##' @details If pars does not contain all `i` values, they will be ##' imputed with zeros. The desired matrix dimension is inferred -##' from `min(i)` and `max(i)`. In case `dt.subset=="unique"` +##' from `min(i)` and `max(i)`. In case `dt.subset=="unique"` ##' missing `j` elements will also give imputations of missing -##' elements. +##' elements. ##' @import data.table ##' @return a matrix ##' @export @@ -62,8 +65,21 @@ dt2mat <- function(pars,dt.subset="unique",max.i,fill=0,col.value) { i.missing <- setdiff(min(pars$i):max.i,pars$i) pars.mat <- rbind(pars.mat,data.table(i=i.missing,j=i.missing),fill=TRUE) + + ## note, dcast returns a keyed data.table (keys are LHS vars) so it is always ordered by i. - matrix.pars <- as.matrix(dcast(pars.mat,i~j,value.var="value")[,!("i")]) + pars.matshape <- dcast(pars.mat,i~j,value.var="value")[,!("i")] + matrix.pars <- matrix(unlist(pars.matshape),ncol=nrow(pars.matshape)) + + if(F){ + if(nrow(pars.matshape)==1){ + ## matrix.pars <- matrix(pars.matshape) + matrix.pars <- matrix(as.numeric(unlist(pars.matshape))) + } else { + matrix.pars <- as.matrix(pars.matshape) + } + } + if(!isFALSE(fill)){ matrix.pars[is.na(matrix.pars)] <- fill } diff --git a/devel/scripts/dsCreate_1.R b/devel/scripts/dsCreate_1.R index ae540832..d89a4c78 100644 --- a/devel/scripts/dsCreate_1.R +++ b/devel/scripts/dsCreate_1.R @@ -15,6 +15,7 @@ library(ggplot2) ## install_github("philipdelff/NMdata") ## library(NMdata) +setwd("~/wdirs/NMdata/devel/scripts/") library(devtools) load_all("~/wdirs/NMdata") @@ -310,3 +311,13 @@ NMwriteSection(file.nm("xgxr001dir/input.txt"),section="DATA",newlines=sec.data. ### Section end: Create xgxr001dir +#### Section start: Version with AMT in microgram #### + +### xgxgr002: CYCLE=DROP, BBW for WEIGHTB +pk2 <- copy(pk) +pk2[,AMT:=AMT*1000] +nmcode <- NMwriteData(pk2,file=file.data.test("xgxr12.csv"),script=script.1,args.stamp = list(description="AMT in micrograms")) + + +### Section end: Version with AMT in microgram + diff --git a/man/dt2mat.Rd b/man/dt2mat.Rd index 2b82bac4..f4e56a7c 100644 --- a/man/dt2mat.Rd +++ b/man/dt2mat.Rd @@ -14,7 +14,10 @@ and `j` with row and column indexes and `est` with parameter \item{dt.subset}{Specifies whether pars contains only a lower or upper triangle of an assumed symmetric matrix (most often the case for variance-covariance matrices), or it contains the -full matrix.} +full matrix. `dt.subset="unique"` (default) means that `pars` only +contains either upper or lower diagonal matrix (including +diagonal), `dt.subset="all"` means `pars` contains both upper +and lower triangles. See details.} \item{max.i}{By default, the maximum row number is derived as he maximum value in the `i` column. If more (empty ones) are @@ -39,7 +42,7 @@ further calculations. \details{ If pars does not contain all `i` values, they will be imputed with zeros. The desired matrix dimension is inferred - from `min(i)` and `max(i)`. In case `dt.subset=="unique"` + from `min(i)` and `max(i)`. In case `dt.subset=="unique"` missing `j` elements will also give imputations of missing elements. }