GxP Compliance in Pharma Made Easier: Good Documentation Practices with R Markdown and {officedown}

Estimated time:
time
min

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. <ul><li><a href="#anchor-1" target="_blank" rel="noopener noreferrer">GxP documentation and reporting</a></li><li><a href="#anchor-2" target="_blank" rel="noopener noreferrer">R Markdown and GxP compliance</a></li><li><a href="#anchor-3" target="_blank" rel="noopener noreferrer">{officedown} in GxP environments</a></li><li><a href="#anchor-4" target="_blank" rel="noopener noreferrer">GxP compliance with {officedown}</a></li><li><a href="#anchor-5" target="_blank" rel="noopener noreferrer">{officedown} for easier GxP document management</a></li></ul> <h2 id="anchor-1">GxP documentation and reporting</h2> Accurate, reliable, and visible data is at the center of <a href="https://www.fda.gov/media/71553/download" target="_blank" rel="noopener noreferrer">pharmaceutical quality systems</a>. From the earliest stages of product research and development, GxP helps ensure continuous improvement and proper risk management in the drug manufacturing process. <h3>What is GxP</h3> 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: <ul><li style="font-weight: 400;" aria-level="1">GCP: Good Clinical Practice</li><li style="font-weight: 400;" aria-level="1">GCDMP: Good Clinical Data Management Practice</li><li style="font-weight: 400;" aria-level="1">GMP: Good Manufacturing Practice</li><li style="font-weight: 400;" aria-level="1">GLP: Good Laboratory Practice</li><li style="font-weight: 400;" aria-level="1">GTP: Good Tissue Practice</li></ul> 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 (<a href="https://www.fda.gov/regulatory-information/search-fda-guidance-documents/clinical-trials-guidance-documents" target="_blank" rel="noopener noreferrer">FDA</a>) in the U.S. and the European Medicines Agency (<a href="https://www.ema.europa.eu/en/human-regulatory/research-development/compliance/good-manufacturing-practice/guidance-good-manufacturing-practice-good-distribution-practice-questions-answers" target="_blank" rel="noopener noreferrer">EMA</a>) in the European Union. <h3>GxP reporting in regulated industries: challenges</h3> 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: <ol><li style="font-weight: 400;" aria-level="1"><b>Traceability:</b>the ability to trace the whole product lifecycle, complete with all changes.</li><li style="font-weight: 400;" aria-level="1"><b>Accountability:</b>the ability to identify all contributors and provide timestamps for each change.</li><li style="font-weight: 400;" aria-level="1"><b>Data Integrity:</b>the reliability of data generated by the system.</li></ol> 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. <h2 id="anchor-2">R Markdown and GxP compliance</h2> R Markdown is a file format for making dynamic documents with R. Under the hood, R Markdown file is processed by the {<a href="https://yihui.org/knitr/" target="_blank" rel="noopener noreferrer">knitr</a>} package into a Markdown document. It’s then processed by <a href="https://pandoc.org/" target="_blank" rel="noopener noreferrer">Pandoc</a> that renders the final document. Both Markdown and Pandoc are independent of the R environment. <img class="aligncenter wp-image-8142 size-full" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b02015afc0ff7c657ab70e_image1_r-markdown-document-pipeline.webp" alt="r markdown document workflow" width="709" height="120" /> 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. <h3>Benefits of using R Markdown</h3> Using R Markdown, your regulatory documents, such as clinical trial reports, are: <ul><li style="font-weight: 400;" aria-level="1"><b>Automated</b>:avoid spending time on repeatable tasks and mundane manual report creation.</li><li style="font-weight: 400;" aria-level="1"><b>Reproducible</b>:anyone can regenerate the report with the same or new data.</li><li style="font-weight: 400;" aria-level="1"><b>Testable</b>:tests can be introduced to ensure that data is valid or that the report structure follows guidelines.</li><li style="font-weight: 400;" aria-level="1"><b>Available in multiple formats</b>:Word, PowerPoint, PDF, HTML documents can be easily created.</li><li style="font-weight: 400;" aria-level="1"><b>RxP compliant</b>:automation options include a default requirement of assigning an author to each generated report.</li></ul> What’s more, you can use <a href="https://rmarkdown.rstudio.com/" target="_blank" rel="noopener noreferrer">RStudio Connect to deploy R Markdown</a> files with one click of a button. The files are then automatically rendered and you can easily share them 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. <h3>R Markdown limitations</h3> At some point you may be requested to change your reports for GxP regulations: <ul><li style="font-weight: 400;" aria-level="1">“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”</li><li style="font-weight: 400;" aria-level="1">“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.”</li><li style="font-weight: 400;" aria-level="1">“Any changeable data has to be formatted as italic blue, regardless if it is in a table or in the text.”</li></ul> It may become very difficult to comply with such detailed guidelines with vanilla R Markdown as it’s not that flexible. <h2 id="anchor-3">{officedown} in GxP environments</h2> With the <a href="https://ardata-fr.github.io/officeverse/officedown-for-word.html" target="_blank" rel="noopener noreferrer">{officedown}</a> 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 <a href="https://davidgohel.github.io/officer/" target="_blank" rel="noopener noreferrer">{officer}</a> 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. <img class="aligncenter size-full wp-image-8143" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b0201704abfeee1f0620cd_image2_officeverse-packages.webp" alt="office verse packages" width="709" height="221" /> With <a href="https://ardata-fr.github.io/mschart/" target="_blank" rel="noopener noreferrer">{mschart}</a>, you can create editable charts, much like those featured in an Excel spreadsheet. The <a href="https://ardata-fr.github.io/flextable-book/" target="_blank" rel="noopener noreferrer">{flextable}</a> interface is an extremely convenient way to create highly customizable tables. <h2 id="anchor-4">GxP compliance with {officedown}</h2> 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. <h3>Fine control of document structure</h3> 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. <a href="https://github.com/rstudio/pagedown" target="_blank" rel="noopener noreferrer">{pagedown}</a> 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. <img class="aligncenter size-full wp-image-8144" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b020186bb6e6a6629cba2c_image3_document-structure.webp" alt="screencapture of R script and document structure output" width="1921" height="969" /> <h3>Styling text and tables</h3> 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. <img class="aligncenter size-full wp-image-8145" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b0201a7a16ac39e34bface_image4_styling-text-and-tables.webp" alt="screencapture of R script and styling of text and tables output" width="1920" height="968" /> <h3>Styling documents using templates</h3> 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. <img class="aligncenter size-full wp-image-8146" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b0201a00b05468d71c740a_image5_styling-docs-using-templates.webp" alt="view of transforming .docx file with {officedown}" width="1839" height="959" /> <h3>Combining multiple documents</h3> 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. <img class="aligncenter size-full wp-image-8147" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b0201bc8798807239f2050_image6_combining-docs.webp" alt="screencapture of R script and combining multiple docs output" width="1921" height="967" /> <h3>Landscape page</h3> 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. <img class="aligncenter size-full wp-image-8148" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b0201ce6755ca41b312b91_image7_landscape-pages.webp" alt="screencapture of R script and landscape doc output" width="2048" height="1119" /> <h2 id="anchor-5">{officedown} for easier GxP document management</h2> 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: <ul><li style="font-weight: 400;" aria-level="1">more control over document layout and structure</li><li style="font-weight: 400;" aria-level="1">robust formatting of text and tables</li><li style="font-weight: 400;" aria-level="1">global application of custom styles in reports</li><li style="font-weight: 400;" aria-level="1">convenient compilation of multiple documents</li></ul> 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. <h2 id="anchor-6">Need more R insights to optimize your data management system?</h2> Appsilon is a top destination for <a href="https://appsilon.com/5-great-shiny-dashboards/" target="_blank" rel="noopener noreferrer">R Shiny dashboards</a> and <a href="https://appsilon.com/computer-vision/" target="_blank" rel="noopener noreferrer">computer vision</a> 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 help us support clients with custom data management solutions. Sharing our <a href="https://appsilon.com/shiny/" target="_blank" rel="noopener noreferrer">R Shiny</a> know-how in the form of <a href="https://appsilon.com/open-source-overview/" target="_blank" rel="noopener noreferrer">open source tools</a> and <a href="https://appsilon.com/shiny-templates-available/" target="_blank" rel="noopener noreferrer">Shiny Dashboard Templates</a> is our way of giving back to the <a href="https://appsilon.com/appsilon-talks-r-medicine-conference-automation-focus/" target="_blank" rel="noopener noreferrer">R community</a>. If there is anything your data science team would like to discuss - let us know!

Contact us!
Damian's Avatar
Damian Rodziewicz
Head of Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
open source
pharma
r
community