Categories: Big Data

Learn R – Hello World with R – Code Example

This article represents some of the basic concepts required to be understood to write Hello world using R programming language and, execute the same. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.

Following are the key points described later in this article:

  • Basic Concepts to Write Hello World Function in R
  • Hello World – Code Example
Basic Concepts to Write Hello World Function in R

Following are some key points to pay attention at, while working Hello World example:

  • R code is written as a set of one or more functions.
  • In R, one could assign a function to any variable
  • A function is defined using a “function” keyword
  • R code is called as a script and saved with *.R extension
  • The R script is executed using source command shown later in this article

 

Hello World – Code Example

Following is code example for Hello world. Pay attention to some of the following:

  • Usage of sprintf function to print Hello World
  • The way, argument “name” is passed to the function

 

hello <- function( name ) {
    sprintf( "Hello, %s", name );
}

Follow the instructions below to execute the script:

  • Click on File > New script that opens a window where you could write your script. Copy and paste the above script in the file.
  • Save the file as, may be, helloworld.R
  • Go to command prompt in R console, and write following command to execute the script.
    source("Path_to_the_file")
    

    In case of windows, use “\\” to escape the back slash.

  • Execute command, hello(“Calvin”)
  • This would print Hello, Calvin

 

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

Recent Posts

Retrieval Augmented Generation (RAG) & LLM: Examples

Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…

4 days ago

How to Setup MEAN App with LangChain.js

Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…

1 week ago

Build AI Chatbots for SAAS Using LLMs, RAG, Multi-Agent Frameworks

Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…

2 weeks ago

Creating a RAG Application Using LangGraph: Example Code

Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…

3 weeks ago

Building a RAG Application with LangChain: Example Code

The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…

3 weeks ago

Building an OpenAI Chatbot with LangChain

Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…

3 weeks ago