title: Getting java.io.IOException errors running an R scraper script
body: <p>I have this sample <code>R</code> scraper script (I can't use actual website):</p>
  
  <pre><code>#!/usr/bin/Rscript
  
  library(RCurl)
  library(httr)
  library(rvest)
  library(lubridate)
  library(stringi)
  
  new_files &lt;- Map(function(ln, y, bn) {
  
    fun1 &lt;- html_session(URLencode(
      paste0("https://example.com", ln)),
      config(ssl_verifypeer = FALSE))
  
    if(y == Sys.Date()) {writeBin(fun1$response$content, bn)}
      else ("He's dead, Jim")
  
    return(fun1$response$content)
  
  }, links, dates, names)
  </code></pre>
  
  <p>I'm running this script in a docker container, through Apache NiFi (the <code>ExecuteProcessor</code> processor). But when I set it to run, I keep getting this error: </p>
  
  <pre><code>Process execution failed due to java.io.IOException: Stream closed: java.io.IOException: Stream closed
       java.io.IOException: Stream closed 
    at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at org.apache.nifi.processors.standard.ExecuteProcess$4.call(ExecuteProcess.java:367)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  
  <p>I was reading <a href="https://stackoverflow.com/questions/32943897/java-ioexception-stream-closed?rq=1">this answer on closing streams</a> before they should be closed. I have no idea why this would be throwing a closed exception error, when the script works fine on my local computer / in RStudio. </p>
  
  <p>It messes up as soon as it's executed in a docker container. Something to do with my if/else statement within the <code>Map</code> function? I have no clue - or it has something to do with loading the <code>lubridate</code> package. </p>