Skip to content

Commit

Permalink
version 0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff authored and cran-robot committed Nov 11, 2023
1 parent c384b74 commit 31d8d51
Show file tree
Hide file tree
Showing 230 changed files with 52,301 additions and 1,054 deletions.
6 changes: 3 additions & 3 deletions 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.4
Version: 0.0.5
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 All @@ -17,8 +17,8 @@ BugReports: https://github.com/philipdelff/NMsim/issues
Language: en-US
URL: https://philipdelff.github.io/NMsim/
NeedsCompilation: no
Packaged: 2023-09-21 00:08:34 UTC; philip
Packaged: 2023-11-11 03:18:52 UTC; philipde
Author: Philip Delff [aut, cre],
Matthew Fidler [ctb] (Co-author on NMreadCov)
Repository: CRAN
Date/Publication: 2023-09-21 06:50:13 UTC
Date/Publication: 2023-11-11 07:03:20 UTC
259 changes: 225 additions & 34 deletions MD5

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(NMsim_known)
export(NMsim_typical)
export(addEVID2)
export(addResVar)
export(genPhiFile)
export(inputArchiveDefault)
import(MASS)
import(NMdata)
Expand Down
33 changes: 30 additions & 3 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
# Post 0.0.1
# 0.0.5
## New features

* NMsim supports type.sim="typical" which means all OMEGAS will be
* Full support for models estimated with SAEM. Especially, simulation
of "known" subjects, i.e. re-using emperical Bayes estimates, is
slightly different with these models.

* Experimental support for windows with PsN. `dir.psn` argument has to
point to a directory where executables `execute` and `update_inits`
are found. Thanks to Sjoerd Koopman for debugging and testing
this. Hopefully in future versions, `PsN` will not be needed on
Windows (like it is not needed on Linux).

* The simulation method called NMsim_known now accepts other `.phi`
files to use than the .phi file generated by the estimation
run. This is useful if one wants to reuse subjects generated in a
previous simulation.

## Other/minor improvements

* NMexec now also copies out the shk (shrinkage estimates) file after
a run. The files that will by default be copied and reported next to
the control streams are now `xml`, `ext`, `cov`, `cor`, `coi`,
`phi`, `shk` - in addition to output table files and the archived
input data of course.

# 0.0.2
## New features

* NMsim supports `type.sim="typical"` which means all OMEGAS will be
fixed to zero. This requires the ext file to be present.

* Experimental support for simulation of estimated subjects using type.sim="known".
* Experimental support for simulation of estimated subjects using
`type.sim="known"`.
1 change: 0 additions & 1 deletion R/NMcreateMatLines.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
##' @keywords internal

NMcreateMatLines <- function(omegas,type){

. <- NULL
j <- NULL
i <- NULL
Expand Down
62 changes: 44 additions & 18 deletions R/NMexec.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
##' to be available for further processing.
##' @param args.psn.execute A character string with arguments passed
##' to execute. Default is
##' "-model_dir_name -nm_output=xml,ext,cov,cor,coi,phi".
##' "-model_dir_name -nm_output=xml,ext,cov,cor,coi,phi,shk".
##' @param update.only Only run model(s) if control stream or data
##' updated since last run?
##' @param nmquiet Suppress terminal output from `Nonmem`. This is
Expand Down Expand Up @@ -69,16 +69,19 @@
##' installed version of PSN).
##' @param path.nonmem The path to the nonmem executable. Only used if
##' \code{method.execute="direct"} or
##' \code{method.execute="nmsim"} (which is not default). If
##' this argument is not supplied, NMexec will try to run nmfe75,
##' \code{method.execute="nmsim"} (which is not default). If this
##' argument is not supplied, NMexec will try to run nmfe75,
##' i.e. this has to be available in the path of the underlying
##' shell. The default value can be modified using
##' \code{NMdata::NMdataConf}, like
##' \code{NMdataConf(path.nonmem="/path/to/nonmem")}
##' @param files.needed In case method.execute="nmsim", this
##' argument specifies files to be copied into the temporary
##' directory before Nonmem is run. Input control stream and
##' simulation input data does not need to be specified.
##' @param files.needed In case method.execute="nmsim", this argument
##' specifies files to be copied into the temporary directory
##' before Nonmem is run. Input control stream and simulation
##' input data does not need to be specified.
##' @param system.type A charachter string, either \"windows\" or
##' \"linux\" - case insensitive. Windows is only experimentally
##' supported. Default is to use \code{Sys.info()[["sysname"]]}.
##' @details Use this to read the archived input data when retrieving
##' the nonmem results:
##' \code{NMdataConf(file.data=inputArchiveDefault)}
Expand Down Expand Up @@ -114,7 +117,7 @@
NMexec <- function(files,file.pattern,dir,sge=TRUE,input.archive,
nc=64,dir.data=NULL,wait=FALSE, args.psn.execute,
update.only=FALSE,nmquiet=FALSE,
method.execute="psn",dir.psn,path.nonmem,
method.execute="psn",dir.psn,path.nonmem,system.type,
files.needed){


Expand Down Expand Up @@ -162,11 +165,14 @@ NMexec <- function(files,file.pattern,dir,sge=TRUE,input.archive,
input.archive <- function(file) FALSE
}

if(missing(system.type)) system.type <- NULL
system.type <- getSystemType(system.type)

## args.psn.execute
if(missing(args.psn.execute)) args.psn.execute <- NULL
args.psn.execute <- simpleCharArg("args.psn.execute"
,args.psn.execute
,default="-model_dir_name -nm_output=xml,ext,cov,cor,coi,phi"
,default="-model_dir_name -nm_output=xml,ext,cov,cor,coi,phi,shk"
,accepted=NULL
,clean=FALSE
,lower=FALSE)
Expand All @@ -187,6 +193,8 @@ NMexec <- function(files,file.pattern,dir,sge=TRUE,input.archive,
,accepted=NULL
,clean=FALSE
,lower=FALSE)



if(is.null(files) && is.null(file.pattern)) file.pattern <- ".+\\.mod"
files.all <- NMdata:::getFilePaths(files=files,file.pattern=file.pattern,dir=dir,quiet=TRUE)
Expand Down Expand Up @@ -222,9 +230,15 @@ NMexec <- function(files,file.pattern,dir,sge=TRUE,input.archive,
saveRDS(dat.inp,file=file.path(rundir,basename(fn.input)))
}


if(method.execute=="psn"){
## string.cmd <- paste0("cd ",rundir,"; ",cmd.execute ,args.execute)
string.cmd <- sprintf("cd %s; %s %s",rundir,cmd.execute ,args.psn.execute)
##if(system.tpe=="linux"){

string.cmd <- sprintf('cd "%s"; "%s" %s',rundir,cmd.execute ,args.psn.execute)
##}
## if(system.type=="windows"){
## pas
## }
if(sge){
string.cmd <- paste0(string.cmd," -run_on_sge")
if(nc>1){
Expand All @@ -249,8 +263,8 @@ NMexec <- function(files,file.pattern,dir,sge=TRUE,input.archive,
if(sge) {

## string.cmd <- sprintf("cd %s; qsub -terse -wd \'%s\' %s",getwd(),dirname(string.cmd),string.cmd)
#### I am not sure if absolute path is needed here.
string.cmd <- sprintf("cd %s; qsub -terse -wd \'%s\' %s",
## I am not sure if absolute path is needed here.
string.cmd <- sprintf('cd "%s"; qsub -terse -wd \'%s\' %s',
getwd(),getAbsolutePath(dirname(string.cmd)),string.cmd)
## string.cmd <- paste0("CURWD=",getwd()," ",string.cmd)
wait <- TRUE
Expand All @@ -259,11 +273,23 @@ NMexec <- function(files,file.pattern,dir,sge=TRUE,input.archive,
}
}

if(nmquiet) string.cmd <- paste(string.cmd, ">/dev/null 2>&1")

if(!wait) string.cmd <- paste(string.cmd,"&")

system(string.cmd,ignore.stdout=nmquiet)
if(system.type=="windows"){

## contents.bat <- gsub(";","\n",string.cmd)
## cat(contents.bat,file=path.script)
path.script <- file.path(dirname(file.mod),"NMsim_exec.bat")
contents.bat <-
strsplit(string.cmd,split=";")[[1]]
writeTextFile(contents.bat,file=path.script)

shell(shQuote(path.script,type="cmd") )
}
if(system.type=="linux"){
if(nmquiet) string.cmd <- paste(string.cmd, ">/dev/null 2>&1")
if(!wait) string.cmd <- paste(string.cmd,"&")

system(string.cmd,ignore.stdout=nmquiet)
}
}

return(invisible(NULL))
Expand Down
9 changes: 5 additions & 4 deletions R/NMexecDirectory.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ NMexecDirectory <- function(file.mod,path.nonmem,files.needed,dir.data=".."){
meta.tables <- NMscanTables(file.mod.tmp,meta.only=TRUE,as.fun="data.table")

### execute nonmem
exts.cp <- c("lst","xml","ext","cov","cor","coi","phi","msf","msfi","msfo" )
exts.cp <- c("lst","xml","ext","cov","cor","coi","phi","msf","msfi","msfo","shk" )

dir.mod.abs <- getAbsolutePath(dir.mod)
lines.bash <- c(
Expand All @@ -123,9 +123,10 @@ NMexecDirectory <- function(file.mod,path.nonmem,files.needed,dir.data=".."){
)

path.script <- file.path(dir.tmp,"run_nonmem.sh")
con.newfile <- file(path.script,"wb")
writeLines(lines.bash,con=con.newfile)
close(con.newfile)
## con.newfile <- file(path.script,"wb")
## writeLines(lines.bash,con=con.newfile)
## close(con.newfile)
writeTextFile(lines.bash,path.script)
Sys.chmod(path.script,mode="0577")

## system(path.script)
Expand Down
2 changes: 1 addition & 1 deletion R/NMreadPhi.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
##' Read information from Nonmem ext files
##' Read information from Nonmem phi files
##'
##' @param file Path to the phi file
##'
Expand Down

0 comments on commit 31d8d51

Please sign in to comment.