Closed verajosemanuel closed 7 years ago
@verajosemanuel can you post a small reproducible example of this? I'm not sure what is happening here. Why is as.POSIXlt
being called?
File > New File > Rnotebook. Just added code for loading tidyquant package this way:
---
title: "R Notebook"
output: html_notebook
---
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Cmd+Shift+Enter*.
```{r}
library(tidyquant)
plot(cars)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
Hmm, I can render this just fine. I rendered using RStudio's Knit to HTML button and from the command line using Terminal. Both worked for me.
Which version of tidyquant are you running? I would try a clean install using install.packages(tidyquant)
. I ran with 0.5.3 and it worked.
Also make sure that pandoc is up to date. On Mac I can update with brew install pandoc
. I think at least version 1.12.3 is required to render, although I doubt this is the problem.
I'm most interested in why as.POSIXlt()
is trying to do anything. tidyquant
doesn't do anything like that when its attached. Can you provide any more information on this from your end?
From the console in RStudio, can you library(tidyquant)
without any errors?
A potentially similar issue here. This may have to do with lubridate
? tidyquant
does depend on lubridate
(it loads lubridate when loading tidyquant) some I'm wondering if thats it.
Try and replace library(tidyquant)
with library(lubridate)
and try and render again.
Hi @DavisVaughan , I can load library with no issue at console. The issue only arises loading tidyquant, not lubridate.
Regards
@verajosemanuel, I just spun up my AWS Linux server with RStudio on it and tried this. It worked with no issues. My sessionInfo()
was fairly similar to yours.
The last thing I would recommend is reinstalling all of the packages that tidyquant depends on.
If that doesn't work, try recreating the problem on another computer. If you cannot, I'm going to have to conclude that this is an issue with your machine, and not with tidyquant. Sorry about this.
sorry but reinstalling didn't work. The only way of making code work was removing library load and using tidyquant:: on every function call, I Imagine this avoids somehow the call to as.POSIXlt
Thanks
FWIW, I have the same problem. Windows x64 machine, rendering .Rmd to html:
library(tidyquant)
which causes the problem and only when rendering markdown to html (and other outputs)example: a simple .Rmd file:
---
title: "R Notebook"
output:
html_document:
df_print: paged
---
```{r}
library(tidyquant)
packageVersion("tidyquant")
produces this:
output file: tidyquant-fail.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS tidyquant-fail.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output tidyquant-fail.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\Rtmp4et7mu\rmarkdown-str40643d2c664b.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
Output created: tidyquant-fail.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
``
output file: tidyquant-fail.knit.md
packageVersion("tidyquant")
[1] ‘0.5.3’
@pjc42
Would you believe me if I had a guess that it was the rmarkdown
package?
Both base
R and lubridate
use the date()
function.
tidyquant
loads lubridate
when library-ed
Rendering an rmarkdown document calls rmarkdown::render()
render()
actually has a call to date()
in it that is not fully specified by base::date()
. I'm worried there might be a collision that is happening for you for some reason.
Update) Even more evidence is that cat()
is the first thing to call the object that would contain the errored date()
result. That would explain the traceback you posted.
Humor me, try and install my fork of rmarkdown
where I have specified base::date()
.
devtools::install_github("DavisVaughan/rmarkdown")
Then give R a restart just to be sure. Then try and knit the document again.
Davis, hi. Thanks for the quick response. Happy to help if I can.
I tried your version of rmarkdown
but the error persisted.
I does appear that the issue is lubridate
though. I get the same error message just using library(lubridate)
no tidyquant
involved at all.
If I had to guess, and that is all I'm doing because I'm not qualified, is that the RStudio R process created by the "Knit to HTML" is creating a .Last
function for the session that includes the problem call to date(). I am not sure how to check this so purely a guess from the console output of the knitr process.
Consider following couple of examples:
In[1]
---
title: "R Notebook"
output: html_document
---
```{r}
library(rmarkdown)
Out[1]
Sat Sep 23 21:44:13 2017
source .Rprofile: C:/Users/pjc/Documents/.Rprofile
|...................... | 33%
ordinary text without R code
processing file: junk5.Rmd
|........................................... | 67%
label: unnamed-chunk-1
|.................................................................| 100%
ordinary text without R code
output file: junk5.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS junk5.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output junk5.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\Rtmpu2XT56\rmarkdown-str12d43f952e5c.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
done: Sat Sep 23 21:44:14 2017
Output created: junk5.html
this example fails on what looks like the call that should have produced something like:
done: Sat Sep 23 21:44:14 2017
Maybe this Calls: .Last -> cat -> date -> date.default -> as.POSIXlt
means it is the R process .Last
function that has the problem call?
`` In[2]
---
title: "R Notebook"
output: html_document
---
```{r}
library(lubridate)
Out[2]
Sat Sep 23 21:47:59 2017
source .Rprofile: C:/Users/pjc/Documents/.Rprofile
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: unnamed-chunk-1
processing file: junk5.Rmd
|.................................................................| 100%
ordinary text without R code
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS junk5.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output junk5.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\RtmpcvK0hW\rmarkdown-str8078564b526c.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
output file: junk5.knit.md
Output created: junk5.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
for the record, the rmarkdown version
> packageDescription("rmarkdown")
Package: rmarkdown
Type: Package
Title: Dynamic Documents for R
Version: 1.6.0.9004
Authors@R: c( person("JJ", "Allaire", role = c("aut", "cre"), email = "jj@rstudio.com"), person("Joe", "Cheng", role = "aut", email = "joe@rstudio.com"), person("Yihui", "Xie", role = "aut", email =
"yihui@rstudio.com"), person("Jonathan", "McPherson", role = "aut", email = "jonathan@rstudio.com"), person("Winston", "Chang", role = "aut", email = "winston@rstudio.com"), person("Jeff",
"Allen", role = "aut", email = "jeff@rstudio.com"), person("Hadley", "Wickham", role = "aut", email = "hadley@rstudio.com"), person("Aron", "Atkins", role = "aut", email = "aron@rstudio.com"),
person("Rob", "Hyndman", role = "aut", email = "Rob.Hyndman@monash.edu"), person("Ruben", "Arslan", role = "aut", email = "ruben.arslan@uni-goettingen.de"), person(family = "RStudio, Inc.", role
= "cph"), person(family = "jQuery Foundation", role = "cph", comment = "jQuery library"), person(family = "jQuery contributors", role = c("ctb", "cph"), comment = "jQuery library; authors listed
in inst/rmd/h/jquery-AUTHORS.txt"), person(family = "jQuery UI contributors", role = c("ctb", "cph"), comment = "jQuery UI library; authors listed in inst/rmd/h/jqueryui-AUTHORS.txt"),
person("Mark", "Otto", role = "ctb", comment = "Bootstrap library"), person("Jacob", "Thornton", role = "ctb", comment = "Bootstrap library"), person(family = "Bootstrap contributors", role =
"ctb", comment = "Bootstrap library"), person(family = "Twitter, Inc", role = "cph", comment = "Bootstrap library"), person("Alexander", "Farkas", role = c("ctb", "cph"), comment = "html5shiv
library"), person("Scott", "Jehl", role = c("ctb", "cph"), comment = "Respond.js library"), person("Ivan", "Sagalaev", role = c("ctb", "cph"), comment = "highlight.js library"), person("Greg",
"Franko", role = c("ctb", "cph"), comment = "tocify library"), person("Eli", "Grey", role = c("ctb", "cph"), comment = "FileSaver library"), person("John", "MacFarlane", role = c("ctb", "cph"),
comment = "Pandoc templates"), person(family = "Google, Inc.", role = c("ctb", "cph"), comment = "ioslides library"), person("Dave", "Raggett", role = "ctb", comment = "slidy library"),
person(family = "W3C", role = "cph", comment = "slidy library"), person("Dave", "Gandy", role = c("ctb", "cph"), comment = "Font-Awesome"), person("Ben", "Sperry", role = "ctb", comment =
"Ionicons"), person(family = "Drifty", role = "cph", comment = "Ionicons"), person("Aidan", "Lister", role = c("ctb", "cph"), comment = "jQuery StickyTabs") )
Author: JJ Allaire, Jonathan McPherson, Yihui Xie, Hadley Wickham, Joe Cheng, Jeff Allen
Maintainer: JJ Allaire <jj@rstudio.com>
Description: Convert R Markdown documents into a variety of formats.
Depends: R (>= 3.0)
Imports: tools, utils, knitr (>= 1.14), yaml (>= 2.1.5), htmltools (>= 0.3.5), caTools, evaluate (>= 0.8), base64enc, jsonlite, rprojroot, methods, stringr (>= 1.2.0)
Suggests: shiny (>= 0.11), tufte, testthat, digest, tibble
SystemRequirements: pandoc (>= 1.12.3) - http://pandoc.org
URL: http://rmarkdown.rstudio.com
License: GPL-3
RoxygenNote: 6.0.1
Built: R 3.4.1; ; 2017-09-24 04:28:04 UTC; windows
RemoteType: github
RemoteHost: https://api.github.com
RemoteRepo: rmarkdown
RemoteUsername: DavisVaughan
RemoteRef: master
RemoteSha: f85ba35a099edf7ade89cea95817826d2d1492e5
GithubRepo: rmarkdown
GithubUsername: DavisVaughan
GithubRef: master
GithubSHA1: f85ba35a099edf7ade89cea95817826d2d1492e5
-- File: C:/Users/pjc/Documents/R/win-library/3.4/rmarkdown/Meta/package.rds
@pjc42, glad to know we've at least tracked this down to lubridate
+ something else.
I'd like to figure out exactly what else is the problem. I want to figure out which package that date()
call is coming from.
Can you run the following:
rmarkdown::render("path_to_file.Rmd")
And when that fails, try running:
traceback()
Interestingly, on my Mac and my version of RStudio and all the packages, I don't get that done: Sat Sep 23 21:44:14 2017
output even if it works. This is likely why i dont have the problem and you do.
@DavisVaughan, good morning.
Rendering manually from a script works. What's different? - from the console output below you can see there are no bracketing calls with start and end time-date of the rendering and as you note these are the calls causing the issue.
Again, I'm guessing but I think that this makes it even more clear that the issue is coming from the call in RStudio from Knit to HTML
menu item that creates a new R process to run the rmarkdown::render("path_to_file.Rmd")
call.
RStudio itself must be adding something equivalent to:
.First <- function() {... start date/info ...}
.Last <- function() {... end data/time info cat() with problem date() call...}
I am using RStudio: Version 1.1.364
anyway, to facts, here is what I get when I run the render directly:
> rmarkdown::render("eg-lubridate-knitr-issue.Rmd")
processing file: eg-lubridate-knitr-issue.Rmd
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: unnamed-chunk-1
|.................................................................| 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\RtmpWcoZi7\rmarkdown-str6b6c770e5a85.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
Output created: eg-lubridate-knitr-issue.html
I posted a question on RStudio
community see here: RStudio - knit to html / lubridate issue.
I have another guess! Do you have an .Rprofile
somewhere?? It runs at startup and runs .Last()
right before shutting down. The example there even shows using .Last
which calls cat
which calls date()
.
http://www.statmethods.net/interface/customizing.html
Even more, an issue on lubridate
reported this exact problem.
https://github.com/tidyverse/lubridate/issues/570
Check your home directory, and on a Mac I can do file.edit(~/.Rprofile)
to open mine up.
Edit) Based on your post it should be here C:/Users/pjc/Documents/.Rprofile
. I am convinced that you DO have an .Rprofile
somewhere and I bet that is the issue.
how embarrassing, spot on.
fixed by removing a helpful date()
in a .Last
function I had defined there.
note even sure why I added the helpful date time call or how long it has been there. probably was pasted from example you link to.
Anyway, thank you for your help and deepest apologies for literally wasting your time...
Glad you got it worked out! Really wish it told you which file the error came from. Would have made life a lot easier.
@verajosemanuel you should check for this too.
Yeah! Confirmed. I've got a date() call in .Last function Solved!
Thanks
Got a very simple Rmd notebook (the demo offered when clicking on menu File > New File > Rnotebook. Just added code for loading tidyquant package. When knitting to HTML Rstudio markdown pane gives me:
Tried to render in putty terminal accessing to server:
r -e "rmarkdown::render('/home/user/R/reporting/report.Rmd')"
Terminal gets cluttered with error and must kill process:
Had to comment library(tidyquant) to get sessionInfo