title: Running R script daily using crontab in OSX
body: <p>I would like to set up a crontab that <strong>runs the emailSender.R script daily at 5pm Monday to Friday.</strong></p>
  
  <p>The script of emailSender.R is as follows:</p>
  
  <pre><code>library(rmarkdown)
  
  rmarkdown::render("htmlmarkdown.Rmd")
  
  
  library(gmailR)
  gmailR::gmail(
    to =c("recipient@email.com"),
    subject = "Subject",
    message = "Message",
    username = "me@email.com",
    password = "password",
    attachment = "htmlmarkdown.html"
  )
  </code></pre>
  
  <p>I then open up terminal to set up the crontab by first typing crontab -e.</p>
  
  <p>Then a window pops up where I try to set up my cronjob using the following code.</p>
  
  <pre><code>0 17 * * * Rscript /Users/username/emailSender.R
  </code></pre>
  
  <p>Unfortunately, emailSender.R doesn't run as scheduled. </p>
  
  <p>Would greatly appreciate any help on getting a crontab to schedule my R script</p>
  
  <p>EDIT: After going back to my terminal and typing Rscript I am prompted: </p>
  
  <pre><code>-bash: Rscript: command not found
  </code></pre>
  
  <p>Perhaps I have to set Rscript in my PATH before cron can set-up the task. Unsure how to do that despite searching extensively. </p>