AnyCompiler

Aapka Pehla R Program

Ek R script mein koi compile step nahi hota aur koi required entry-point function bhi nahi — na main, na class wrapper. Interpreter top-level statements ko order mein run karta hai, jaise hi file execute hoti hai. print() ek value ko waise dikhata hai jaise R use dikhata jab aap use directly ek prompt par type karte — [1] index prefix aur strings ke around quotes including. cat() values ko concatenated likh deta hai bina quotes ke aur bina index prefix ke, aur koi trailing newline add nahi karta jab tak aap khud \n include na karo. Comments # se start hote hain aur line ke end tak chalte hain.

Khud run karo

Yeh actually execute kiya gaya tha neeche dikhaya gaya output nikalne ke liye — text change karke khud run karne ki koshish karo example ke neeche diye button se.

# This is a comment
print("Hello, R!")
cat("No newline here")
cat(" - still same line\n")
Output
[1] "Hello, R!"
No newline here - still same line

Notice karo print() ne "Hello, R!" ko quotes mein wrap kiya aur [1] se prefix kiya (R ka yeh marking karne ka tareeka ki "yeh us vector ka element 1 hai jise aap dekh rahe ho") — print() hamesha aapko value ka structure dikhata hai, sirf uske contents nahi. Dono cat() calls, iske contrast mein, same output line par land hue bilkul bina quotes ke, kyunki cat() khud se kabhi newline add nahi karta aur raw text ke aage kuch nahi dikhata. Aage: vectors and assignment — <- assignment, c(), aur "everything is a vector" practice mein actually kaisa dikhta hai.

Practice exercise

Apne code ke upar ek comment add karo, phir "Learning R one step at a time." print karo.