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 how you can maximize big data in the cloud with Apache Hadoop. Download this eBook now. Brought to you in partnership with Hortonworks.

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

Hortonworks DataFlow is an integrated platform that makes data ingestion fast, easy, and secure. Download the white paper now.  Brought to you in partnership with Hortonworks

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 best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}