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
)
File paths to the models (control stream) to edit. See file.pattern too.
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.
If file.pattern is used, `dir` is the directory to search in.
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.
The new text (including "$SECTION"). Better be
broken into lines in a character vector since this is simply
past to writeLines()
.
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.
In combination with `section`, this determines where the new section is inserted. Possible values are "replace" (default), "before", "after", "first", "last".
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.
In case you are overwriting the old file, do you want to backup the file (to say, backup_run001.mod)?
Append a blank line to output?
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.
Default is to write to file. If write=FALSE, `NMwriteSection()` returns the resulting input.txt without writing it to disk? Default is `FALSE`.
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()`.
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.
The new section text is returned. If write=TRUE, this is done invisibly.
The new file will be written with unix-style line endings.
Other Nonmem:
NMapplyFilters()
,
NMextractText()
,
NMgenText()
,
NMreadSection()
,
NMreplaceDataFile()
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)
if (FALSE) { # \dontrun{
text.nm <- NMwriteData(data)
NMwriteSection(dir="nonmem",
file.pattern="^run.*\\.mod",
list.sections=text.nm["INPUT"])
} # }