Skip to content

Commit

Permalink
Bugfix in NMcreateMatLines
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Sep 14, 2023
1 parent e8baa35 commit 5b335af
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: NMsim
Type: Package
Title: Seamless 'Nonmem' Simulation Platform
Version: 0.0.1.192
Version: 0.0.193
Authors@R: c(person("Philip", "Delff", email = "philip@delff.dk",role = c("aut","cre")),
person("Matthew","Fidler", role = c("ctb"), email = "matt.fidler@novartis.com", comment="Co-author on NMreadCov"))
Maintainer: Philip Delff <philip@delff.dk>
Expand Down
4 changes: 3 additions & 1 deletion R/NMcreateMatLines.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ NMcreateMatLines <- function(omegas,type){
loopres <- c()
Netas <- omegas[,max(i)]



while(i.idx <= length(is)){
i.this <- is[i.idx]
nis.block <- omegas.long[i==i.this,unique(maxOff)]
Expand All @@ -47,7 +49,7 @@ NMcreateMatLines <- function(omegas,type){
values.this[values.this==0] <- 1e-30
res <- paste0("BLOCK(",nis.block+1,") FIX ",paste(values.this,collapse=" "))
loopres <- c(loopres,res)
i.idx <- i.idx+nis.block
i.idx <- i.idx+nis.block+1
} else {
value.this <- omegas.long[i==i.this&j==i.this,value]
res <- paste(value.this)
Expand Down
62 changes: 38 additions & 24 deletions R/NMsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@


NMsim <- function(file.mod,data,dir.sims, name.sim,
order.columns=TRUE,script=NULL,subproblems,
order.columns=TRUE,script=NULL,subproblems=NULL,
reuse.results=FALSE,seed,args.psn.execute,
nmquiet=FALSE,text.table, type.mod,method.sim=NMsim_default,
execute=TRUE,sge=FALSE,transform=NULL ,type.input,
Expand All @@ -211,8 +211,11 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
,...
){#### Section start: Dummy variables, only not to get NOTE's in pacakge checks ####

sim <- NULL
est <- NULL
dir.sim <- NULL
f.exists <- NULL
files.needed <- NULL
fn.sim.tmp <- NULL
fn <- NULL
par.type <- NULL
i <- NULL
Expand All @@ -226,7 +229,7 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
textmod <- NULL
default <- NULL
known <- NULL
typical <- NULL
model <- NULL
psn <- NULL
direct <- NULL
directory <- NULL
Expand All @@ -236,18 +239,16 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
fn.sim <- NULL
run.mod <- NULL
run.sim <- NULL
dir.sim <- NULL
f.exists <- NULL
fn.sim.tmp <- NULL
typical <- NULL
path.sim <- NULL
path.digests <- NULL
path.sim.lst <- NULL
fn.data <- NULL
path.data <- NULL
sim <- NULL
value <- NULL
variable <- NULL
ROW <- NULL
files.needed <- NULL
ROWMODEL2 <- NULL

### Section end: Dummy variables, only not to get NOTE's in pacakge checks
Expand All @@ -270,10 +271,8 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
}



## path.nonmem - should use NMdataConf setup

if(missing(path.nonmem)) path.nonmem <- NULL
## path.nonmem
if(missing(path.nonmem)) path.nonmem <- NULL
path.nonmem <- try(NMdata:::NMdataDecideOption("path.nonmem",path.nonmem),silent=TRUE)
if(inherits(path.nonmem,"try-error")){
path.nonmem <- NULL
Expand Down Expand Up @@ -309,9 +308,11 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
if(is.null(method.update.inits)) {
method.update.inits <- "psn"
cmd.update.inits <- file.psn(dir.psn,"update_inits")

## check if update_inits is avail
## if(suppressWarnings(system(paste(cmd.update.inits,"-h"),show.output.on.console=FALSE)!=0)){
if(!file.exists(cmd.update.inits)){
which.found <- system(paste("which",cmd.update.inits),ignore.stdout=T)
if(which.found!=0){
method.update.inits <- "nmsim"
rm(cmd.update.inits)
}
Expand All @@ -337,7 +338,15 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
}
if(missing(name.sim)) name.sim <- NULL
name.sim <- simpleCharArg("name.sim",name.sim,"noname",accepted=NULL,lower=FALSE)


## modelname
## if(missing(modelname)){
modelname <- NULL
## }
file.mod.named <- FALSE
if(!is.null(names(file.mod))){
file.mod.named <- TRUE
}

## as.fun
if(missing(as.fun)) as.fun <- NULL
Expand All @@ -354,9 +363,9 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
}


## if(F){
if(length(file.mod)>1){
allres.l <- lapply(file.mod,NMsim
allres.l <- lapply(1:length(file.mod),function(x)
NMsim(file.mod=file.mod[[x]],
,data=data
,dir.sims=dir.sims,
name.sim=name.sim,
Expand All @@ -368,16 +377,20 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
text.table=text.table,
type.mod=type.mod,execute=execute,
sge=sge
## ,modelname=modelname
,transform=transform
##,type.sim=type.sim
,method.sim=method.sim
,path.nonmem=path.nonmem
,dir.psn=dir.psn
,...
)
))
if(file.mod.named){
names.mod <- names(file.mod)
allres.l <- lapply(1:length(allres.l),function(I) allres.l[[I]][,model:=names.mod[[I]]])
}
return(rbindlist(allres.l,fill=TRUE))
}
## }




Expand Down Expand Up @@ -418,12 +431,13 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
dt.models[,fn.sim:=paste0("NMsim_",fn.mod)]
## dt.models[,fn.sim:=paste0(fn.mod)]
dt.models[,fn.sim:=fnAppend(fn.sim,name.sim)]


## run.mod <- sub("\\.mod","",basename(file.mod))
if(missing(modelname)) modelname <- NULL
## modelname <- NMdataDecideOption("modelname",modelname)
if(is.null(modelname)) modelname <- function(fn) fnExtension(basename(fn),"")

dt.models[,run.mod:=fnExtension(basename(file.mod),"")]
## run.sim <- sub("\\.mod","",fn.sim)
dt.models[,run.sim:=fnExtension(basename(fn.sim),"")]
dt.models[,run.sim:=modelname(fn.sim)]


## dir.sim is the model-individual directory in which the model will be run
Expand Down Expand Up @@ -611,7 +625,7 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
dt.files <- melt(dt.models.gen,measure.vars=c("path.sim",cols.fneed),value.name="file")
dt.files[,missing:=!file.exists(file)]
if(dt.files[,sum(missing)]){
message(print(dt.files[,.("No. of files missing"=sum(missing)),by=.(column=variable)]))
message(dt.files[,.("No. of files missing"=sum(missing)),by=.(column=variable)])
stop("All needed files must be available after running simulation method.")
}

Expand Down Expand Up @@ -730,7 +744,7 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
}
### Section end: Execute

if(!wait) return(simres$ls)
## if(!wait) return(simres$lst)
as.fun(simres)

}
2 changes: 1 addition & 1 deletion man/NMsim.Rd

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

0 comments on commit 5b335af

Please sign in to comment.