title: Writing a different csv file in R using If Else Statement
body: <p>I am having trouble writing a different csv file in R based on the actual day of the week. If today is Saturday, I want to write <code>df1</code>, otherwise I want to write <code>df2</code>.</p>
  <p>I have my data like so:</p>
  <pre><code>df1 &lt;- data.frame(Fruit = c(&quot;Apples&quot;, &quot;Apples&quot;, &quot;Apples&quot;, &quot;Oranges&quot;, &quot;Oranges&quot;, &quot;Bananas&quot;, &quot;Bananas&quot;),
                    No. = c(2,8,7,1,4,9,6))
  
  df2 &lt;- data.frame(Fruit = c(&quot;Apples&quot;, &quot;Apples&quot;, &quot;Apples&quot;, &quot;Oranges&quot;, &quot;Oranges&quot;, &quot;Bananas&quot;, &quot;Bananas&quot;),
                    No. = c(4,16,21,46,6,18,9))
  </code></pre>
  <p>I have tried using if else like so:</p>
  <pre><code>ifelse(format(Sys.time(), &quot;%a&quot;) == &quot;Sat&quot;, write.csv(df1, &quot;data-today.csv&quot;, quote = FALSE, row.names = FALSE), 
         write.csv(df2, &quot;data-today.csv&quot;, quote = FALSE, row.names = FALSE))
  </code></pre>
  <p>But it returns this error:</p>
  <pre><code>Error in ans[npos] &lt;- rep(no, length.out = len)[npos] :  
    replacement has length zero
  In addition: warning message:
  In rep(no, length.out=len) : 'x' is NULL so the result will be NULL
  </code></pre>
  <p>Is there a way this can be achieved?</p>