title: R Hadoop mapper error subscript out of bounds
body: <p>I am trying to write a basic MapReduce using R (Hadoop Streaming). The following is the Mapper function I have written:</p>
  
  <pre><code>#! /usr/bin/env Rscript
  
  con &lt;- file("stdin",open = "r")
  
  while(length(line &lt;- readLines(con = con,n = 1,warn = FALSE)) &gt; 0 )
  {
    line1 &lt;- gsub("^\\s+|\\s+$", "", line)
    if(is.null(strsplit(line1," ")) == FALSE){
      x &lt;- as.numeric(unlist(strsplit(line1," "))[[1]])
      y &lt;- as.numeric(unlist(strsplit(line1," "))[[2]])
      x2 &lt;- x*x
      xy &lt;- x*y
      cat(x,"\t",y,"\t",xy,"\t",x2,"\n")   
    }
  }
  
  close(con)
  </code></pre>
  
  <p>The input file for this contains two columns as given below:</p>
  
  <pre><code>1  15.55511341
  2   27.53983952
  3   39.7767569
  4   47.44065279
  5   55.0606804
  6   68.57527802
  7   77.03639749
  8   80.92939421
  9   94.4431412
  10  106.5353655
  </code></pre>
  
  <p>I tried running this mapper directly on command prompt using the following command:</p>
  
  <pre><code>cat ../data/Input.txt | ./mapper.R
  </code></pre>
  
  <p>However, I get the following error message:</p>
  
  <pre><code>Error in unlist(strsplit(line1, " "))[[2]] : subscript out of bounds
    In addition: Warning message:
    NAs introduced by coercion 
    Execution halted
  </code></pre>
  
  <p>It looks like I am making some basic mistakes in the code. Could someone please help me with this issue?</p>