Skip to content

This book provides a comprehensive guide to best coding practices in R, focusing on essential aspects like script organisation, naming conventions, commenting, and version control. It aims to enhance the readability, maintainability, and collaborative potential of R code by offering practical advice on creating well-structured and clean scripts.

Notifications You must be signed in to change notification settings

MOPAC-DS/Learning-Resource-Best-Coding-Practices-in-R

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Best Coding Practices in R

Welcome to the "Best Coding Practices in R" book! This book provides a comprehensive guide to best coding practices in R, focusing on essential aspects like script organisation, naming conventions, commenting, and version control. It aims to enhance the readability, maintainability, and collaborative potential of R code by offering practical advice on creating well-structured and clean scripts.

Table of Contents

  1. Introduction

    • Why Coding Practices Matter
    • What This Book Covers
    • How to Use This Book
    • Who This Book Is For
    • Final Thoughts
  2. Naming Conventions

    • Naming Scripts
    • Naming Variables
    • Naming Functions
    • Consistency is Key
    • Summary
  3. Organising Scripts

    • Structuring Scripts
    • Organising Files and Directories
    • Documentation
    • Summary
  4. Commenting Code

    • The Purpose of Comments
    • Best Practices for Commenting
    • Common Pitfalls to Avoid
    • Advanced Commenting Techniques
    • Summary
  5. Code Syntax and Spacing

    • Importance of Consistent Syntax
    • Indentation
    • Spacing
    • Line Breaks
    • Aligning Code
    • Comment Placement and Spacing
    • Avoiding Common Pitfalls
    • Summary
  6. Writing Functions

    • The Purpose of Functions
    • Structure of a Function
    • Documentation and Commenting
    • Testing Functions
    • Advanced Function Techniques
    • Avoiding Common Pitfalls in Function Writing
    • Summary
  7. Error Handling

    • Introduction to Error Handling
    • Basic Error Handling with try and tryCatch
    • Custom Error Messages with stop, warning, and message
    • Defensive Programming
    • Best Practices for Error Handling
    • Summary
  8. Version Control with Git

    • Introduction to Git
    • Setting Up Git
    • Basic Git Workflow
    • Branching and Merging
    • Working with Remote Repositories
    • Advanced Git Features
    • Git in RStudio
    • Best Practices for Using Git
    • Summary
  9. Reproducibility and Documentation

    • Introduction to Reproducibility
    • Setting Up a Reproducible Environment
    • Sharing Your Work
    • Documentation for Reproducibility
    • Case Study: Reproducible Analysis in R
    • Summary
  10. Conclusion

  • Recap of Key Concepts
  • The Importance of Adopting Best Practices
  • Moving Forward
  • Final Thoughts

How to Access

You can access the full book online via the following link: Best Coding Practices in R

Installation

To view the book locally, you will need to clone this repository and render the Bookdown project. Follow these steps:

  1. Clone the Repository

    git clone [https://github.com/MOPAC-DS/Learning-Resource-Best-Coding-Practices-in-R.git](https://github.com/MOPAC-DS/Learning-Resource-Best-Coding-Practices-in-R)
  2. Install Required Packages

Make sure you have R and the necessary packages installed. You can install them using:

install.packages(c("bookdown", "tidyverse", "ggplot2"))
  1. Render the Book

Open R or RStudio and set your working directory to the cloned repository. Then run:

bookdown::render_book("index.Rmd")

This will generate the book in various formats (HTML, PDF, etc.).

Contributing

Contributions are welcome! If you have suggestions for improvements or spot any issues, please open an issue or submit a pull request.

Contact

For questions or feedback, please contact Daniel Hammocks via email daniel.hammocks@mopac.london.gov.uk.

License

This book is licensed under the MIT License.

About

This book provides a comprehensive guide to best coding practices in R, focusing on essential aspects like script organisation, naming conventions, commenting, and version control. It aims to enhance the readability, maintainability, and collaborative potential of R code by offering practical advice on creating well-structured and clean scripts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published