Just give the section name, the new lines and the file path, and the "$section", and the input to Nonmem will be updated.

NMwriteSection(
  files,
  file.pattern,
  dir,
  section,
  newlines,
  list.sections,
  location = "replace",
  newfile,
  backup = TRUE,
  blank.append = TRUE,
  data.file,
  write = TRUE,
  quiet,
  simplify = TRUE
)

Arguments

files

File paths to the models (control stream) to edit. See file.pattern too.

file.pattern

Alternatively to files, you can supply a regular expression which will be passed to list.files as the pattern argument. If this is used, use `dir` argument as well. Also see data.file to only process models that use a specific data file.

dir

If file.pattern is used, `dir` is the directory to search in.

section

The name of the section to update with or without "$". Example: `section="EST"` or `section="$EST"` to edit the sections starting by `$EST`. Section specification is not case-sensitive. See `?NMreadSection` too.

newlines

The new text (including "$SECTION"). Better be broken into lines in a character vector since this is simply past to writeLines().

list.sections

Named list of new sections, each element containing a section. Names must be section names, contents of each element are the new section lines for each section.

location

In combination with `section`, this determines where the new section is inserted. Possible values are "replace" (default), "before", "after", "first", "last".

newfile

path and filename to new run. If missing, the original file (from files or file.pattern) is overwritten (see the backup option below). If NULL, output is returned as a character vector rather than written.

backup

In case you are overwriting the old file, do you want to backup the file (to say, backup_run001.mod)?

blank.append

Append a blank line to output?

data.file

Use this to limit the scope of models to those that use a specific input data data file. The string has to exactly match the one in `$DATA` or `$INFILE` in Nonmem.

write

Default is to write to file. If write=FALSE, `NMwriteSection()` returns the resulting input.txt without writing it to disk? Default is `FALSE`.

quiet

The default is to give some information along the way on what data is found. But consider setting this to TRUE for non-interactive use. Default can be configured using `NMdataConf()`.

simplify

If TRUE (default) and only one file is edited, the resulting rows are returned directly. If more than one file is edited, the result will always be a list with one element per file.

Value

The new section text is returned. If write=TRUE, this is done invisibly.

Details

The new file will be written with unix-style line endings.

Examples

newlines <- "$EST POSTHOC INTERACTION METHOD=1 NOABORT PRINT=5 MAXEVAL=9999 SIG=3"
NMwriteSection(files=system.file("examples/nonmem/xgxr001.mod", package = "NMdata"),
section="EST", newlines=newlines,newfile=NULL)
#> Writing 
if (FALSE) {
text.nm <- NMwriteData(data)
NMwriteSection(dir="nonmem",
              file.pattern="^run.*\\.mod",
              list.sections=text.nm["INPUT"])
}