Skip to content

Commit

Permalink
support for first and last + bugfix for first section
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Nov 30, 2024
1 parent e3fad06 commit 9ddd6ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 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.8.901
Version: 0.1.8.902
Authors@R:
c(person(given="Philip", family="Delff",
email = "philip@delff.dk",
Expand Down
2 changes: 1 addition & 1 deletion R/NMwriteSection.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ NMwriteSection <- function(files,file.pattern,dir,section,newlines,
list.sections,location="replace",newfile,
backup=TRUE,blank.append=TRUE,data.file,
write=TRUE,quiet,simplify=TRUE){



#### Section start: handle arguments ####
Expand Down
15 changes: 8 additions & 7 deletions R/NMwriteSectionOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ NMwriteSectionOne <- function(file0,lines,section,location="replace",
min.dl <- min(idx.dlines)
max.dl <- max(idx.dlines)

### these two cases need to be handled slightly differently so not supported for now

stopifnot(min.dl>1)
}
nlines <- length(lines)

Expand Down Expand Up @@ -109,17 +106,21 @@ NMwriteSectionOne <- function(file0,lines,section,location="replace",
}
if(location=="after"){

all.lines <- c(lines,newlines)
if(min.dl>1){
##
## if(min.dl>1){
if(max.dl<nlines){
all.lines <- c(lines[1:(max.dl)],
newlines,
lines[-(1:(max.dl))]
## lines[max((max.dl+1),length(lines)):length(lines)]
)
} else {
all.lines <- lines
all.lines <- c(lines,newlines)
}
}
if(location=="first"){
all.lines <- c(newlines,lines)
}
if(location=="last"){
all.lines <- c(lines,newlines)
}
Expand All @@ -130,7 +131,7 @@ NMwriteSectionOne <- function(file0,lines,section,location="replace",
for (I in 1:length(list.sections)) {
newlines <- replaceOnePart(lines=newlines,section=names(list.sections)[I],
newlines=list.sections[[I]]
,quiet=quiet)
,quiet=quiet)
}

if(is.null(newfile)) return(newlines)
Expand Down

0 comments on commit 9ddd6ed

Please sign in to comment.