Skip to contents

Execute Nonmem from within R - optionally but by default in parallel. Archiving the input data ensures that postprocessing can still be reproduced if the input data files should be updated.


  sge = TRUE,
  nc = 64, = NULL,
  wait = FALSE,
  update.only = FALSE,
  nmquiet = FALSE,
  method.execute = "psn",
  quiet = FALSE



File paths to the models (control streams) to run nonmem on. 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 for control streams in.


Use the sge queing system. Default is TRUE. Disable for quick models not to wait for the queue to run the job.


A function of the model file path to generate the path in which to archive the input data as RDS. Set to NULL not to archive the data.


Number of cores to use if sending to the cluster. This will only be used if method.execute="psn", and sge=TRUE. Default is 64.

The directory in which the data file is stored. This is normally not needed as data will be found using the path in the control stream. This argument may be removed in the future since it should not be needed.


Wait for process to finish before making R console available again? This is useful if calling NMexec from a function that needs to wait for the output of the Nonmem run to be available for further processing.


A character string with arguments passed to execute. Default is "-model_dir_name -nm_output=xml,ext,cov,cor,coi,phi,shk".


Only run model(s) if control stream or data updated since last run?


Suppress terminal output from `Nonmem`. This is likely to only work on linux/unix systems.


How to run Nonmem. Must be one of 'psn', 'nmsim', or 'direct'.

  • psn PSN's execute is used. This supports parallel Nonmem runs. Use the nc argument to control how many cores to use for each job. For estimation runs, this is most likely the better choice, if you have PSN installed. See dir.psn argument too.

  • nmsim Creates a temporary directory and runs Nonmem inside that directory before copying relevant results files back to the folder where the input control stream was. If sge=TRUE, the job will be submitted to a cluster, but parallel execution of the job itself is not supported. See path.nonmem argument too.

  • direct Nonmem is called directly on the control stream. This is the simplest method and is the least convenient in most cases. It does not offer parallel runs and leaves all the Nonmem output files next to the control streams.

See `sge` as well.


The directory in which to find PSN executables. This is only needed if these are not searchable in the system path, or if the user should want to be explicit about where to find them (i.e. want to use a specific installed version of PSN).


The path to the nonmem executable. Only used if method.execute="direct" or method.execute="nmsim" (which is not default). If this argument is not supplied, NMexec will try to run nmfe75, i.e. this has to be available in the path of the underlying shell. The default value can be modified using NMdata::NMdataConf, like NMdataConf(path.nonmem="/path/to/nonmem")


A charachter string, either \"windows\" or \"linux\" - case insensitive. Windows is only experimentally supported. Default is to use[["sysname"]].


In case method.execute="nmsim", this argument specifies files to be copied into the temporary directory before Nonmem is run. Input control stream and simulation input data does not need to be specified.


Suppress messages on what NMexec is doing? Default is FALSE.


NULL (invisibly)


Use this to read the archived input data when retrieving the nonmem results: NMdataConf(

Since `NMexec` will typically not be used for simulations directly (`NMsim` is the natural interface for that purpose), the default method for `NMexec` is currently to use `method.execute="psn"` which is at this point the only of the methods that allow for multi-core execution of a single Nonmem job (NB: `method.execute="NMsim"` can run multiple jobs in parallel which is normally sufficient for simulations).


file.mod <- "run001.mod"
if (FALSE) {
## run locally - not on cluster
## run on cluster with 16 cores. 64 cores is default
## submit multiple models to cluster
multiple.models <- c("run001.mod","run002.mod")
## run all models called run001.mod - run099.mod if updated. 64 cores to each.