modify_records: Modify or retrieve options and records from a 'NONMEM'...

modify_recordsR Documentation

Modify or retrieve options and records from a NONMEM control stream file

Description

Modify or retrieve options and records from a NONMEM control stream file

Usage

get_model_ctl(.mod)

get_records(.mod, type, get_lines = FALSE)

mod_has_record(.mod, type)

remove_records(.mod, type)

add_new_record(
  .mod,
  type,
  rec_name = paste0("$", toupper(type), " "),
  lines = NULL,
  after = NULL
)

modify_data_path_ctl(.mod, data_path)

modify_prob_statement(.mod, prob_text = NULL)

get_input_columns(.mod, from_data = TRUE)

get_table_columns(.mod, from_data = TRUE)

Arguments

.mod

a bbr model object

type

record type. This may be spelled any way that's accepted in a NONMEM control stream.

get_lines

Logical (T/F). If TRUE, return the lines as character vectors (based on how they were defined in the control stream).

rec_name

a character string defining the record name (e.g., ⁠$THETA⁠)

lines

a character string or vector of lines to append to the new record. If passing a vector, creates a new line per index. Defaults to NULL.

after

add new record after this record type. This may be spelled any way that's accepted in a NONMEM control stream. If NULL, append to the end of the control stream. If multiple records are found, uses the last index

data_path

Data path to set in a ⁠$DATA⁠ record.

prob_text

If NULL return the current ⁠$PROBLEM⁠ statement. If a character string, set the problem statement to that value.

from_data

Logical (T/F). If TRUE, the default, get the column names from the first line of the referenced dataset (input data or table file). If FALSE, parse the control stream and retrieve from the relevant record type (⁠$INPUT⁠ or ⁠$TABLE⁠).

Details

  • get_model_ctl() is called internally within the other functions, though it can also be used outside of that context.

  • modify_prob_statement(), modify_data_path_ctl(), remove_records(), and add_new_record() read in the control stream, make any modifications, and then save out the updated control stream.

    • modify_prob_statement() also returns a character string defining the ⁠$PROBLEM⁠ text (see prob_text argument).

  • mod_has_record() will return a logical value denoting whether a bbr model has a given record type.

  • get_records() extracts all records of a given type. Note that it is not meant to be used to modify existing records.

  • get_input_columns() and get_table_columns() extract the column names of the input data and all table files respectively. They can either be parsed from a NONMEM control stream file, or determined from reading in the csvs/table files. See from_data argument for more details.

Functions

  • get_model_ctl(): Read in a NONMEM control stream file, parsed via nmrec

  • get_records(): Pull all records of a given record type from a bbr model

  • mod_has_record(): Check if a bbr model has a given record type

  • remove_records(): Remove all records of a given type from a NONMEM control stream file

  • add_new_record(): Add a new record of a given type from a NONMEM control stream file

  • modify_data_path_ctl(): Modify the specified data path in a NONMEM control stream file

  • modify_prob_statement(): Modify or retrieve the ⁠$PROBLEM⁠ statement from a NONMEM control stream file.

  • get_input_columns(): Retrieve input data column names from either the ⁠$INPUT⁠ record in a NONMEM control stream file or the input dataset.

  • get_table_columns(): Retrieve table columns names from either ⁠$TABLE⁠ record(s) in a NONMEM control stream file or the tabled out files

Note

Run the following command to see what record types are available/supported by nmrec:

`ls(nmrec:::record_names)`

See Also

assert_record_type()

Examples

## Not run: 

# Adding a new record
seed <- 1234; n <- 100
sim_lines <- glue("({seed}) SUBPROBLEMS={n} TRUE=FINAL ONLYSIMULATION")
add_new_record(.mod, "simulation", lines = sim_lines, after = "pred")


# Remove all records of a given type
if(mod_has_record(.mod, "table")) remove_records(.mod, "table")


# Modify or extract a problem statement
modify_prob_statement(.mod, prob_text = NULL)
#> [1] "PK model 1 cmt base"
modify_prob_statement(.mod, prob_text = "new problem")
#> [1] "new problem"


## End(Not run)

metrumresearchgroup/bbr documentation built on March 29, 2025, 1:08 p.m.