data.table column expression breaks in easyHtmlReport, works in plain knitr

276 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

@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.

1
On

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     <-  "[email protected]"
to       <-  "[email protected]"
subject  <-  "Test"
message  <-  markdownToHTML(knit("Test.Rmd"))
send.mail(from,to,subject,message,html=TRUE,smtp=list( host.name="smtp.test.com"))