🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
1. Introduction
Taking user input is a fundamental aspect of interactive programming. Whether you're writing scripts for data analysis or building tools, the ability to capture and utilize user input can make your programs more flexible and user-friendly.
2. Program Overview
In this post, we will be creating an R program that captures input from a user and displays it back. We'll be utilizing R's built-in functions to achieve this simple yet crucial task.
3. Code Program
# Prompt the user for input
cat("Please enter your name: ")
# Use the readline function to get the input from the user
user_input <- readline()
# Display the input back to the user
cat("Hello,", user_input, "! Welcome to the R program.\n")
Output:
Please enter your name: John Hello, John ! Welcome to the R program.
4. Step By Step Explanation
1. We use the cat() function to display a message prompting the user to enter their name. The cat() function in R is used to concatenate and display its arguments.
# Prompt the user for input
cat("Please enter your name: ")
2. The readline() function is used to capture input from the user. This function reads a line from the console (terminal) and can be stored in a variable for future use.
# Use the readline function to get the input from the user
user_input <- readline()
3. Finally, we use the cat() function again to display a message back to the user, incorporating the input we just captured. This gives a personalized greeting based on the user's input.
# Display the input back to the user
cat("Hello,", user_input, "! Welcome to the R program.\n")
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment