Skip to content

Commit

Permalink
NMreadExt reports only last table by default
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Dec 22, 2023
1 parent 4939072 commit ccae3fd
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 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.3.911
Version: 0.1.3.912
Authors@R: c(person("Philip", "Delff", email = "philip@delff.dk", role = c("aut", "cre")))
Maintainer: Philip Delff <philip@delff.dk>
Description: Efficient tools for preparation, checking and post-processing of data in PK/PD (pharmacokinetics/pharmacodynamics) modeling, with focus on use of Nonmem. Attention is paid to ensure consistency, traceability, and Nonmem compatibility of Data. Rigorously checks final Nonmem datasets. Implemented in 'data.table', but easily integrated with 'base' and 'tidyverse'.
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ tables.
options or function arguments but it will now work either way. An
error will be thrown if both should be found.

* `NMreadExt` will by default only return parameters and iterations
from the last table available. This can be controlled by the
`tableno` argument.

* `fnAppend` will now throw an error in case the file name extension
cannot be identified.

Expand Down
37 changes: 36 additions & 1 deletion R/NMreadExt.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@
##' something else. If data.tables are wanted, use
##' as.fun="data.table". The default can be configured using
##' NMdataConf.
##' @param tableno In case the ext file contains multiple tables, this argument controls which one to choose. The options are
##' \itemize{
##'
##' \item "max" (default) Pick the table with the highest table
##' number. This typically means the results from the last
##' `$ESTIMATION` step are used.
##'
##' \item "min" Pick results from the first table available.
##'
##' \item "all" Keep all results. The tables can be distinguished by
##' the `tableno` column.
##'
##' \item an integer greater than 0, in which case the table with this
##' table number will be picked.
##' }
##' @param modelname See ?NMscanData
##' @param col.model See ?NMscanData
##' @param auto.ext If TRUE (default) the extension will automatically
Expand All @@ -25,7 +40,7 @@
##' @import data.table
##' @export

NMreadExt <- function(file,return="pars",as.fun,modelname,col.model,auto.ext,file.ext){
NMreadExt <- function(file,return="pars",as.fun,modelname,col.model,auto.ext,tableno="max",file.ext){

#### Section start: Dummy variables, only not to get NOTE's in pacakge checks ####

Expand All @@ -50,6 +65,13 @@ NMreadExt <- function(file,return="pars",as.fun,modelname,col.model,auto.ext,fil
modelname <- NMdataDecideOption("modelname",modelname)
if(missing(auto.ext) || is.null(auto.ext)) auto.ext <- TRUE

if(is.null(tableno)) tableno <- "max"

if(! (is.character(tableno)&&tableno%in%c("min","max","all") ) ||
(is.numeric(tableno) && tableno>0 && tableno%%1==0) ){
stop("tableno must be either one of the character strings min, max, all or an integer greater than zero.")
}

args <- getArgs()
if(missing(file.ext)) file.ext <- NULL
file <- deprecatedArg("file.ext","file",args=args)
Expand Down Expand Up @@ -84,6 +106,19 @@ NMreadExt <- function(file,return="pars",as.fun,modelname,col.model,auto.ext,fil
this.model <- modelname(file)
NMreadTab(file,as.fun="data.table",quiet=TRUE,col.table.name=TRUE)[,(col.model):=this.model]
})

if(tableno=="min"){
res.NMdat <- lapply(res.NMdat,function(x)x[TABLENO==min(TABLENO)])
}
if(tableno=="max"){
res.NMdat <- lapply(res.NMdat,function(x)x[TABLENO==max(TABLENO)])
}
if(is.numeric(tableno)){
res.NMdat <- lapply(res.NMdat,function(x)x[TABLENO==tableno])
}



res.NMdat <- rbindlist(res.NMdat,fill=TRUE)

## NONMEM USERS GUIDE
Expand Down
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ reference:
- NMstamp
- NMwriteSection
- NMreplaceDataFile
- colLabels
- title: Retrieve NONMEM data
desc: Functions for retrieving NONMEM input and output data
contents:
Expand All @@ -75,6 +76,7 @@ reference:
- NMreadExt
- NMreadPhi
- NMreadTab
- NMreadParsText
- NMinfo
- title: Checking and Debugging
desc: Functions for checking data and input control streams
Expand Down
17 changes: 17 additions & 0 deletions man/NMreadExt.Rd

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

Binary file modified tests/testthat/testReference/NMreadExt_05.rds
Binary file not shown.

0 comments on commit ccae3fd

Please sign in to comment.