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

How to Simplify Apache Kafka. Get eBook.

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

12 Best Practices for Modern Data Ingestion. Download White Paper.

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

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}