GxP Compliance in Pharma Made Easier: Good Documentation Practices with R Markdown and {officedown}
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Consumer safety and product reliability are top of mind for regulated manufacturing industries, including pharmaceuticals. Documenting key processes, like clinical trials and laboratory tests, is critical and calls for a systematic approach. That’s where GxP comes in, with a strong focus on Good Documentation Practices. This globally recognized standard for quality guidelines and compliance requirements can be further optimized with programmatic solutions offered by R packages. In this article, we’re taking a closer look at how R Markdown and {officedown} can help you create, format, and manage GxP compliant documents with precision and confidence.
- GxP documentation and reporting
- R Markdown and GxP compliance
- {officedown} in GxP environments
- GxP compliance with {officedown}
- {officedown} for easier GxP document management
GxP documentation and reporting
Accurate, reliable, and visible data is at the center of pharmaceutical quality systems. From the earliest stages of product research and development, GxP helps ensure continuous improvement and proper risk management in the drug manufacturing process.
What is GxP
GxP stands for Good “x” Practice, where “x” can be C for “Clinical”, L for “Laboratory”, R for “Review”, M for “Manufacturing” and so on. Some common GxPs in the pharmaceutical industry include:
- GCP: Good Clinical Practice
- GCDMP: Good Clinical Data Management Practice
- GMP: Good Manufacturing Practice
- GLP: Good Laboratory Practice
- GTP: Good Tissue Practice
The concept of GxP has been introduced to ensure processes meet strict regulatory requirements. Each country has similar guidelines, enforced and audited by a national regulatory body. The most notable agencies regulating pharmaceuticals are the Food and Drug Administration (FDA) in the U.S. and the European Medicines Agency (EMA) in the European Union.
GxP reporting in regulated industries: challenges
Good Documentation Practices (GDocP) are a vital part of GxP compliance. FDA-regulated businesses need to demonstrate to auditors they have an efficient record-keeping and reporting protocol. GDocP should be implemented to define, document, and log every critical action in the development, manufacture, and delivery of a drug or medical device.
GxP documentation requirements target 3 main areas of compliance:
- Traceability:
the ability to trace the whole product lifecycle, complete with all changes. - Accountability:
the ability to identify all contributors and provide timestamps for each change. - Data Integrity:
the reliability of data generated by the system.
According to GxP quality guidelines, each report should include not only the outcome and conclusions but also all the data and data sources used to produce them. That’s why reporting is very prone to errors, especially if documentation is created each time by hand in a copy-paste fashion. Not to mention, manual reporting takes a lot of time and effort. Introducing a Document Management System and programmatically created reports can mitigate those problems.
R Markdown and GxP compliance
R Markdown is a file format for making dynamic documents with R. Under the hood, R Markdown file is processed by the {knitr} package into a Markdown document. It’s then processed by Pandoc that renders the final document. Both Markdown and Pandoc are independent of the R environment.
R Markdown files enable you to create rich and reproducible documents. This element of automation makes R Markdown a powerful tool in the hands of clinical pharmaceutical scientists and technologists.
Benefits of using R Markdown
Using R Markdown, your regulatory documents, such as clinical trial reports, are:
- Automated:
avoid spending time on repeatable tasks and mundane manual report creation. - Reproducible:
anyone can regenerate the report with the same or new data. - Testable:
tests can be introduced to ensure that data is valid or that the report structure follows guidelines. - Available in multiple formats:
Word, PowerPoint, PDF, HTML documents can be easily created. - RxP compliant:
automation options include a default requirement of assigning an author to each generated report.
What’s more, you can use RStudio Connect to deploy R Markdown files with one click of a button. The files are then automatically rendered and can be easily shared as view-only or downloadables. Both render and access events can be monitored and tracked. If a new version of the R Markdown files is available, you can quickly regenerate them. The same automatic process can be also applied periodically.
R Markdown limitations
At some point you may be requested to change your reports for GxP regulations:
- “Please create a page with information on author, date, sources, review. It has to be the first page of the report before the Table of Contents”
- “Page 50 has to be presented as a landscape, we need to include all columns of data and it won’t fit in portrait mode.”
- “Any changeable data has to be formatted as italic blue, regardless if it is in a table or in the text.”
It may become very difficult to comply with such detailed guidelines with vanilla R Markdown as it’s not that flexible.
{officedown} in GxP environments
With the {officedown} package, you can overcome the limitations of R Markdown, like styling specific Word elements. It is better suited for generating Office documents and offers more features for creating and formatting Microsoft Word or PowerPoint documents.
{officedown} includes some of the key features of the {officer} package, built specifically for working with Word and PowerPoint documents. Among other functions, {officer} lets you format blocks of text, apply styles from Microsoft Word, and automatically create cross-references.
Both {officedown} and {officer} packages are a part of a bigger {officeverse}, which is an ecosystem of 4 packages.
With {mschart}, you can create editable charts, much like those featured in an Excel spreadsheet. The {flextable} interface is an extremely convenient way to create highly customizable tables.
GxP compliance with {officedown}
Whenever GxP compliance is key to your research and development process, you can use {officedown} to streamline your documentation workflow. The {officedown} features described below address some of the greatest challenges in Good Documentation Practices.
Fine control of document structure
From a GxP perspective, it may be crucial for the documentation to have a specific order of sections. With R Markdown, you can add a table of contents, but have little control over where it appears. {pagedown} allows you to add not only a TOC but also a list of tables and a list of figures. However, changing the order of those sections is difficult and it’s not possible to export the report as a Word Document.
This is where {officedown} comes in, giving you much more flexibility. It helps you place sections of the report exactly where you want them in the document by using HTML comment tags.
Styling text and tables
Creating editable documents in a research setting may require additional formatting options. For example, you might want to highlight important data, be it text or cells in tables. While styling tables can be done using different packages, the styling of text paragraphs is only possible using {officedown}. By adding a simple variable, you can also automate formatting, e.g. change the highlight color in cells only when the value is lower or higher than the reference value.
Styling documents using templates
With {officedown}, it’s possible to apply styles known from Microsoft Word. Instead of using custom CSS styling, you can create a template .docx file containing styled elements, which is then passed to the YAML header of the R Markdown file. The same styles will be applied to components in the resulting .docx file. This way, the custom formatting you need for your GxP reports or documentation will be automatically included in all newly generated files.
Combining multiple documents
What if you prefer to create a few smaller documents or reports and later compile them into one file? With {officedown}, you can easily append multiple documents into one. What’s more, all references are preserved, while the numbering of sections, figures, and tables is automatically updated and featured in a new table of contents.
Landscape page
Using {officedown} also gives you more flexibility in terms of changing page orientation for selected parts of the report. With a single comment in the code, you can apply the landscape mode to any block in the document. This simple functionality comes in very handy whenever you need to include wide tables or bigger figures.
{officedown} for easier GxP document management
With GxP compliance at stake, automating the process of creating and updating regulatory documents reaches a new level of importance in the pharmaceutical industry. Where manual processes and other packages fall short, {officedown} offers a viable solution. It is a simple and effective way to bring the features of Microsoft Word to R Markdown and unlock custom formatting options.
Let’s recap how {officedown} can help you comply with the GxP requirements:
- more control over document layout and structure
- robust formatting of text and tables
- global application of custom styles in reports
- convenient compilation of multiple documents
These properties of {officedown} translate to a stronger quality system, better risk and change management, and more accurate version control. It’s a win-win for both your R&D team and all the people who rely on the quality of your medical product to recover or lead a healthier life.
Need more R insights to optimize your data management system?
Appsilon is a top destination for R Shiny dashboards and computer vision solutions because of our team of seasoned R developers, software engineers, and front-end developers. It is this hands-on experience with R packages that helps us support clients with custom data management solutions. Sharing our R Shiny know-how in the form of open source tools and dashboard templates is our way of giving back to the R community. If there is anything your data science team would like to discuss – let us know!
Article GxP Compliance in Pharma Made Easier: Good Documentation Practices with R Markdown and {officedown} comes from Appsilon | End to End Data Science Solutions.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.