← Back to R Course | Chapter 1: Getting Started | Lesson 4 of 6

Comments लिखना

एक comment एक hash mark से शुरू होता है और एक note है जिसे R ignore करता है, reader के लिए एक sticky note की तरह। यह बिना बदले बताता है कि आपका code क्या करता है।

In this page:

  1. Comments
Syntax
r
# This is a comment
x <- value  # trailing comment

Comments

R में एक # एक comment शुरू करता है, और उस line पर इसके बाद सब कुछ interpreter ignore करता है। R में कोई multi-line comment syntax नहीं है, इसलिए हर comment line को अपना # चाहिए।

Comments को यह clarify करना चाहिए कि code कोई non-obvious चीज़ क्यों करता है बजाय वह दोहराने के जो code से already clear है।

Note: RStudio और ज़्यादातर editors आपको एक पूरा selected block एक साथ comment/uncomment करने देते हैं, हर line में # add करते हुए।

उदाहरण: Comments

markup
# This script demonstrates comments
x <- 10  # inline comment after code
# print(x) -- this line is commented out and won't run
print(x)
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. comments के लिए // या /* */ इस्तेमाल करने की कोशिश करना, जो R में errors हैं; सिर्फ # एक comment शुरू करता है।
  2. एक single # से एक block comment करने की कोशिश करना और यह भूल जाना कि हर line को अपना # चाहिए।
  3. "a#b" जैसी एक string के अंदर # डालना और सोचना कि यह comment शुरू करता है, जब quotes के अंदर यह ordinary text है।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.