R in Clinical World: WEEK3; Good Coding Practices(GCP) and Naming Convention in R

PinnacleVex KA Analytics
2 min readMay 13, 2021

--

Good Coding Practices(GCP) and Naming Convention in R

1. Must start with a letter (A-Z or a-z); or period(.) always follwed by letter(e.g. ‘.pinnaclevex’, not ‘.9pinnaclevex’).
2. Can contain letters, digits (0–9), and/or periods “.”
3. Use underscores (_) to separate words within a name.
4. Use names that are concise and meaningful (e.g. virus <- ‘covid19’, not virus <- ‘bat’).
5. R is a case sensitive language example Data different from data.

Implementing a consistent coding convention. Basically, there are five naming conventions to choose from
1. underscore_separated: e.g. pinnaclevex_analytics
2. period.separated: e.g. pinnaclevex.analytics
3. all lowercase: e.g. pinnaclevexanalytics
4. lowerCamelCase: e.g. pinnacleVexAnalytics
5. UpperCamelCase: e.g. PinnacleVexAnalytics

It’s better choosing one naming convention and sticking to it. For best practice we decided to use the underscore_separated naming convention because
a. all lowercase names are difficult to read especially for non-native readers.
b. period.separated names are confusing for users of Python and other languages in which dots are meaningful.
c. UpperCamelBack is ugly and requires excessive use of the shift button.

How to organize the code within each file?
1. Start each file with a comment(“#” is used to comment) saying who wrote it and when, what it contains, and how it fits into the larger program.
2. Load all required packages.
3. Source all required files
4. Start coding; break code into separate files (generally <2000–3000 lines).

Two important R packages are available to help you in applying the R coding style best practices:
1.styler: Which allows you to interactively restyle selected text, files, or entire projects includes an RStudio add-in (the easiest way to re-style existing code). It can be installed using the following R code: install.packages(“styler”)

2. lintr: It performs automated checks to confirm that you conform to the style guide. It can be installed using the following R code: install.packages(“lintr”).

Happy Learning !!! :)

Related Articles:

R in Clinical World: WEEK2

R in Clinical World: WEEK1

Introduction to POWER BI

PinnacleVex KA Analytics: BASICS OF MICROSOFT EXCEL

PinnacleVex KA Analytics: Basic Excel Formulas For Your Daily Workflow

PinnacleVex KA Analytics: Simple introduction to SQL

PinnacleVex KA Analytics: Clinical Trials

PinnacleVex KA Analytics Clinical Data Management

My_website

LinkedIn

Youtube

Facebook

Twitter

Instagram

Youtube

--

--

PinnacleVex KA Analytics
PinnacleVex KA Analytics

Written by PinnacleVex KA Analytics

PinnacleVex KA Analytics is a Healthcare and IT Service Provider Headquartered at Hyderabad, India.

No responses yet