title: Error: origin must be supplied
body: <p>I have the following code to clean a dataset.</p>
  
  <pre><code>data1 &lt;- data1 %&gt;% 
    mutate(YEAR = year(DATE), 
           MONTH = month(DATE), 
           DAY=day(DATE), 
           HOUR=hour(TIME), 
           MINUTE = minute(TIME), 
           RETURN= ((PRICE-lag(PRICE))/lag(PRICE))
    ) %&gt;% 
    filter(HOUR &gt;= 9, (HOUR &lt;= 16 &amp; MINUTE &lt;=61)) %&gt;%
    group_by(MINUTE, HOUR, DAY, MONTH, YEAR) %&gt;% 
    summarize(AV.PRICE = mean(PRICE, na.rm=TRUE), 
              SUM.SIZE=sum(SIZE, na.rm=TRUE),
              RV=sum(RET^2)) %&gt;%
    arrange(YEAR, MONTH, DAY, HOUR, MINUTE) %&gt;%
    mutate(DATETIME = as.POSIXct(
      paste(YEAR,"/",MONTH,"/", DAY, " ", HOUR,":", MINUTE,":00",sep=""), 
      format="%Y/%m/%d %H:%M:%S", origin = "1970-01-01")
    )
  </code></pre>
  
  <p>However, it sometimes gives me the error message: <code>Error: 'origin' must be supplied</code></p>
  
  <p>What is strange is that the error does not appear on the first time I run this code in the session, but appears on subsequent runs. If I restart the session, the problem disappears for once and returns in later runs. Hence I have to always restart to get it to work.</p>
  
  <p>I checked the question: <a href="https://stackoverflow.com/questions/19449307/how-to-solve-error-in-as-posixct-numericx2l-origin-must-be-supp">How to solve: &quot;Error in as.POSIXct.numeric(X[[2L]], ...) : &#39;origin&#39; must be supplied&quot;</a> which suggested that it might be because it is converting from integer to time. However a <code>glimpse</code> of the data shows that that the DATE is a <code>&lt;date&gt;</code> class and not an integer. </p>
  
  <p>To be safe: I followed the suggestion of the error and added an origin = "1970-01-01" argument to all of the functions dealing with dates:</p>
  
  <pre><code>data1 &lt;- data1 %&gt;% 
    mutate(YEAR = year(DATE, origin = "1970-01-01"),
           MONTH = month(DATE, origin = "1970-01-01"), 
           DAY=day(DATE, origin = "1970-01-01"), 
           HOUR=hour(TIME, origin = "1970-01-01"),
           MINUTE = minute(TIME, origin = "1970-01-01"), 
           RET= ((PRICE-lag(PRICE))/lag(PRICE))
    ) %&gt;% 
    filter(HOUR &gt;= 9, (HOUR &lt;= 16 &amp; MINUTE &lt;=61)) %&gt;%
    group_by(MINUTE,HOUR,DAY,MONTH,YEAR) %&gt;% 
    summarize(AV.PRICE = mean(PRICE, na.rm=TRUE), 
              SUM.SIZE=sum(SIZE, na.rm=TRUE),
              RV=sum(RET^2)
    ) %&gt;% 
    arrange(YEAR, MONTH, DAY, HOUR, MINUTE) %&gt;% 
    mutate(DATETIME = as.POSIXct(
      paste(YEAR,"/",MONTH,"/", DAY, " ", HOUR,":", MINUTE,":00",sep=""), 
      format="%Y/%m/%d %H:%M:%S", origin = "1970-01-01")
    )
  </code></pre>
  
  <p>and it returns <code>Error: unused argument (origin = "1970-01-01")</code></p>
  
  <p>If it helps, here is a glimpse of my dataset: </p>
  
  <pre><code>Observations: 146,016,609
  Variables: 4
  $ DATE  &lt;date&gt; 2008-01-02, 2008-01-02, 2008-01-02, 2008-01-02, 2008-01-02, 2008-01-02, 2008-01-02, ...
  $ TIME  &lt;S4: Period&gt; 9H 0M 4S, 9H 0M 4S, 9H 0M 4S, 9H 0M 4S, 9H 0M 4S, 9H 0M 4S, 9H 0M 4S, 9H 0M 4S...
  $ PRICE &lt;dbl&gt; 146.86, 146.86, 146.86, 146.86, 146.86, 146.86, 146.86, 146.86, 146.86, 146.86, 146.8...
  $ SIZE  &lt;int&gt; 1000, 1000, 1000, 500, 2400, 1000, 1000, 1000, 2500, 1000, 1000, 400, 1000, 1000, 100...
  </code></pre>
  
  <p>I'm looking for an answer using base package functions or at most lubridate/dplyr. Thanks!</p>