RStudio - knit to html / lubridate issue

hi

not sure if this is the right place to post or even if this a RStudio or lubridate issue.

However, a simple Rmd file with lubridate attached to search path cannot be rendered from Knit to HTML RStudion command. Same file renders fine manually using rmarkdown::render("eg-lubridate-knitr-issue.Rmd").

I'm using RStudion Version 1.1.364.

---
title: "knitr crashes with lubridate"
output: html_document
---


```{r}
library(lubridate)


console output from running Knit to HTML


Mon Sep 25 10:42:33 2017
source .Rprofile: C:/Users/pjc/Documents/.Rprofile

  |......................                                           |  33%
  ordinary text without R code

  |...........................................                      |  67%
label: unnamed-chunk-1


processing file: eg-lubridate-knitr-issue.Rmd
  |.................................................................| 100%
  ordinary text without R code


output file: eg-lubridate-knitr-issue.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS eg-lubridate-knitr-issue.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output eg-lubridate-knitr-issue.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\pjc\Documents\R\win-library\3.4\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "d:\tmp\RtmpWIxStA\rmarkdown-str4c187a9c43f6.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" 

Output created: eg-lubridate-knitr-issue.html
Error in as.POSIXlt(x, tz = tz(x)) : 
  argument "x" is missing, with no default
Calls: .Last -> cat -> date -> date.default -> as.POSIXlt
Execution halted

A guess is that RStudio may be "decorating" R process that is running the render() call with a .Last function with a problem call to date() when lubridate attached because cannot exit RStudio once I've attempted to render the lubridate .Rmd file, presumably because .Last function still failing.

Attempting to quit RStudio from File->Quit Session or q() results in:

Error in as.POSIXlt(x, tz = tz(x)) : 
  argument "x" is missing, with no default

redefining .Last with something that will work, e.g

.Last <- function() {cat("bye")}

runs fixes exit issue

You can follow this issue at tidyquant's github page for more information. I think I may have a solution involving his .Rprofile. See the issue here

1 Like

yes, my bad. The issue was my .Last decoration. I had a helpful .Last function defined with cat("\ndone: ", date(), "\n"). removed this and issue goes away.

Gotta say this is an easy mistake to make.

1 Like