1

I am trying to do some data.table manipulations in an Rmd file. The file works just fine with knit. However, when I run it through easyHtmlReport, it doesn't work: my data.table by expressions fail with ‘Error: object 'userId' not found’, where userId is one of the columns in my data table that I am using in the j expression. The broken expression is:

expt.daystat = expt.users[,list(count=length(userId)),
                          keyby=list(day, status)]

As I said, it works fine in plain knit but breaks in easyHtmlReport.

Matt Dowle
  • 58,872
  • 22
  • 166
  • 224
Michael Ekstrand
  • 28,379
  • 9
  • 61
  • 93
  • 1
    I suspect that this is a bug in the `EasyHTMLReport` package. The `knit` function accepts an `envir` argument that needs to be passed along, and inspecting the code for `easyHtmlReport`, it doesnt seem to be doing that. `data.table` does non-standard evaluation and so bugs like this are most likely due to environments. I would suggest you file a bug report. – Ramnath Feb 10 '14 at 23:53
  • Thanks @Ramnath. I've experimented with adding `envir` code to `EasyHTMLReport`, and it does fix the problem. I've reported the issue to the author. – Michael Ekstrand Feb 15 '14 at 16:53
  • Hi @MichaelEkstrand - I'd appreciate it if you could provide answer to your question. I'm encountering the issue, and my simplistic solution based on your advice was to add `envir=new.env(parent = .GlobalEnv)` into the control argument which doesn't work so seeing your solution would be helpful! – Steph Locke Jul 01 '14 at 13:26
  • @StephLocke I've re-pinged the author about getting the bug fix incorporated into the CRAN version. In the mean time, see answer for the workaround. – Michael Ekstrand Jul 09 '14 at 13:45

2 Answers2

3

@Ramnath is correct. Line 40 of EasyHTMLReport.R is:

knit(input=f,output=md.file)

Update this line with:

knit(input = f, output = md.file, envir = envir)

Update the signature of the function from:

easyHtmlReport <-
    function(rmd.file,from,to,subject,headers=list(),control=list(),
        markdown.options=c("hard_wrap","use_xhtml","smartypants"),
        stylesheet="", echo.disable=TRUE, is.debug=F){

to:

easyHtmlReport <-
    function(rmd.file,from,to,subject,headers=list(),control=list(),
        markdown.options=c("hard_wrap","use_xhtml","smartypants"),
        stylesheet="", echo.disable=TRUE, is.debug=FALSE, envir = parent.frame()){

If you don't want to rebuild the package you should be able to make this change using the edit function.

CSJCampbell
  • 2,025
  • 15
  • 19
3

I wanted to post my alternative solution that I ended up using. It utilises mailR which allows multiple recipients and enables the easy implementation of html without worrying about mime_part commands.

library(mailR)
library(markdown)
library(knitr)

from     <-  "me@me.com"
to       <-  "me@me.com"
subject  <-  "Test"
message  <-  markdownToHTML(knit("Test.Rmd"))
send.mail(from,to,subject,message,html=TRUE,smtp=list( host.name="smtp.test.com"))
Steph Locke
  • 5,951
  • 4
  • 39
  • 77
  • This post gives you some more info. on using mailR with markdown: http://stackoverflow.com/questions/24346856/mailr-how-to-send-rmarkdown-documents-as-body-in-email/24355800#24355800 – Rahul Premraj Jul 11 '14 at 14:37