Introduction

The first step in NONMEM model development is usually to borrow NONMEM code that a colleague who worked on a similar to use code from one of your previous project and then an adapt it to your problem.

This is certainly better than starting from scratch, however consider these problems: the code you borrow where the $EST code is fine for the problem it was originally written for, but works poorly on your problem. Or the file is stylistically different from what you are used to, you may have trouble reading it or the person QCing your work may find it an awkward slow to read/understand. Or little potential issues like perhaps the code didn’t have PRINT=E in the $COV step because it didn’t need and then you are later asked for eigenvalues, requiring you to go back and rerun the final model…

These are all reasons to replace the borrowing from colleague strategy with a maintained code library - a standardised library/directory of templated code that follows best practices and has been reviewed and used by a wide range of people.

Using the code library

Search the code library and bring into staging area of analysis project using the “code_library” RStudio ‘Addin’:

One of the templates is Models/ADVAN2.mod. Select it, preview it and then import by clicking the buttons and then closing the app.

The model will be in the staging area: staging/Models/ADVAN2.mod, not Models/ADVAN2.mod. Files in the staging area are not to be modified. It’s similar to the SourceData directory in that sense. This is to ensure that we can make changes to ADVAN2.mod in the code library without breaking old analyses that depended on it.

Contributing to the code library contained in NMproject

Contributing to the public code library benefits all users and is very much appreciated. There code library is embedded within the NMproject at the following path of the source code: inst/extdata/CodeLibrary. You can browse the code in the link and see what is currently in there.

Do suggest a change one option is to do a pull request or submit an issue through the GitHub interface. If you don’t have a GitHub account or if you’re not familiar with pull requests, the easiest way would be to be email the proposed files to the NMproject maintainer t.sahota0@gmail.com (along with the reasons behind the changes).

Making your own code library

The default code library comes with the NMproject package, however what if you want to maintain your own code library for the organisation or for yourself personally. NMproject caters to this.

See the Configuration & Setup article for information on how to do this.

Using an internal GitHub Enterpise service to host the code library (advanced topic)

If your organisation has GitHub Enterpise, you can host the code library as it’s own repository. The advantage is that your users can use GitHub’s the pull request functionality to propose changes to the repository. For large organistations it is recommend to set a branch protection rule on the master/main branch to avoid users being able to directly modify the code. It is also recommended to add users all users who may contributue to the code library to the repository.

Users then

  1. clone the respository into a local code library repository (e.g. at ~/code_library)

  2. Set the path in NMproject

To update their local respository, they can perform a git pull from the local library location.

To contribute to the respository, they can either use pull requests directly from modifying files on the GitHub Enterprise web interface (this is the easiest way that requests very little GitHub/git knowledge or for more advanced users by modifying their local respository in a separate branch and making a pull request from there (this is useful if lots of changes will happen).

Repository ownsers are then free to define the pull request process that makes sense for the organisation (e.g. two maintainers need to approve for the change to be made)