Skip to content

Commit

Permalink
dt2mat returns matrix objects
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Oct 15, 2024
1 parent a54f61b commit ff92e60
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 20 additions & 4 deletions R/dt2mat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 11 additions & 0 deletions devel/scripts/dsCreate_1.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ library(ggplot2)
## install_github("philipdelff/NMdata")
## library(NMdata)

setwd("~/wdirs/NMdata/devel/scripts/")
library(devtools)
load_all("~/wdirs/NMdata")

Expand Down Expand Up @@ -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

7 changes: 5 additions & 2 deletions man/dt2mat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff92e60

Please sign in to comment.