NONMEM produces a lot of temporary files which can add up to a lot of disk space. One strategy to remove this is to use the clean option in the PsN command. However, this can automatically remove files as soon as the run finishes that may be useful for debugging. ls_tempfiles() allows you to list the paths of all temporary files, for a single run or for all runs for inspection and deletion. clean_tempfiles() is a wrapper function that runs ls_tempfiles() and deletes everything returned. For safety is limited to only deleting files associated with nm objects though.

  object = ".",
  output_loc = c("run_dir", "base"),
  run_files = NA_character_,
  include_slurm_files = TRUE,
  ctl_extension = "mod",
  include_psn_exports = FALSE

clean_run(m, output_loc = c("run_dir", "base"), include_slurm_files = TRUE)

  object = ".",
  output_loc = c("run_dir", "base"),
  include_slurm_files = TRUE



Either an nm object or path to project (default = "."). If a path is specified, the function will look for all runs in the directory (including subdirectories).


Optional character for locating files. Either "run_dir" (default) for PsN execution or "base" for "nmfe" execution.


Optional character vector. Search amongst only these files instead. Default value NA searches based on object.


Logical (default = TRUE). Include files generated by Slurm.


Character. Extension of control file (default = "mod")


Logical (default = FALSE). Considers files that PsN exports to the run_in directory as temporary


An nm object


A character vector of temporary file paths


Setting include_psn_exports = TRUE will break 'Pirana' and 'xpose' capability as these software use exported files.


# create example object m1 from package demo files
exdir <- system.file("extdata", "examples", "theopp", package = "NMproject")
m1 <- new_nm(run_id = "m1",
             based_on = file.path(exdir, "Models", "ADVAN2.mod"),
             data_path = file.path(exdir, "SourceData", "THEOPP.csv"))

ls_tempfiles(m1) ## if no files, will be empty
#> character(0)

m1 %>%
  ls_tempfiles() %>%
  unlink() ## delete all m1 temp files

## above line is equivalent to:

ls_tempfiles() ## display all temp files in analysis project
#> character(0)

ls_tempfiles() %>% unlink() ## remove all temp files in analysis project