Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Learn R: Hello World with R

DZone's Guide to

Learn R: Hello World with R

This article represents some of the basic concepts you need to understand in order to write a Hello world using the R programming language.

· Big Data Zone
Free Resource

Learn best practices according to DataOps. Download the free O'Reilly eBook on building a modern Big Data platform.

This article represents some of the basic concepts you need to understand in order to write a Hello world using the R programming language. Please feel free to comment/suggest if I missed one or more important points.

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

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

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

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

  • Usage of sprintf function to print Hello World
  • The way the 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, which opens a window where you can write your script. Copy and paste the above script in the file.
  • Save the file as, maybe, helloworld.R
  • Go to a command prompt in the R console, and write the following command to execute the script.
    source("Path_to_the_file")
    In Windows, use “\\” to escape the back slash.
  • Execute command hello(“Calvin”)
  • This would print Hello, Calvin

Find the perfect platform for a scalable self-service model to manage Big Data workloads in the Cloud. Download the free O'Reilly eBook to learn more.

Topics:
java ,bigdata ,tips and tricks ,big data

Published at DZone with permission of Ajitesh Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}