Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Comments in R | Basic Syntax and Operations
R Introduction: Part I

Comments in R

When you've written an extensive script for research and need to revisit it later for updates or improvements, remembering the purpose of each line of code can be challenging. That’s where annotations within the code, known as comments, become invaluable.

A comment is a portion of code that isn't executed. To signal which parts should not be processed, we use the # symbol.

For instance, we can add comments in two ways: as a standalone line and alongside a computation:

The console will only show the result of 11 + 3 and ignore all the comments.

While not mandatory, the inclusion of comments is widely regarded as a best practice for maintaining clarity and readability in your code. However, comments should only be used for complicated parts of the code, as excessive commenting can clutter the code and reduce its readability.

Comments are useful not just for clarification, but also for debugging purposes, allowing you to deactivate certain lines of code without deleting them.

Task

To make the code executable by deactivating certain lines, apply the hash # symbol to correct the errors.

Everything was clear?

Section 1. Chapter 4
toggle bottom row
course content

Course Content

R Introduction: Part I

Comments in R

When you've written an extensive script for research and need to revisit it later for updates or improvements, remembering the purpose of each line of code can be challenging. That’s where annotations within the code, known as comments, become invaluable.

A comment is a portion of code that isn't executed. To signal which parts should not be processed, we use the # symbol.

For instance, we can add comments in two ways: as a standalone line and alongside a computation:

The console will only show the result of 11 + 3 and ignore all the comments.

While not mandatory, the inclusion of comments is widely regarded as a best practice for maintaining clarity and readability in your code. However, comments should only be used for complicated parts of the code, as excessive commenting can clutter the code and reduce its readability.

Comments are useful not just for clarification, but also for debugging purposes, allowing you to deactivate certain lines of code without deleting them.

Task

To make the code executable by deactivating certain lines, apply the hash # symbol to correct the errors.

Everything was clear?

Section 1. Chapter 4
toggle bottom row
some-alt