bgreenwell/investr

plotFit within render() or knitr()

TanyaMurphy opened this issue · 4 comments

Hi Brandon, I've really been benefiting from investr. I just ran into a problem with plotFit() when I use it within a knitr script (via render() called by another R script). I'm not completely sure why I have this problem from this particular script and not RStudio's 'knit' button, but anyway I tracked it to the line in plotFit:
eval(object$call$data, sys.frame()) and I get around it back copying my data.frame to the global environment before calling plotFit:
assign("my.df", my.df, envir = .GlobalEnv)

Maybe you can work in a quick fix in the future. Thanks!

Hello Tanya. Glad to know people are using the package! It sounds like an issue with R's scoping rules. Though, I find it odd that using knitr within RStudio causes no issues. I'll try to have it resolved within the next couple of weeks and push a new version to GitHub and CRAN. Thank you for reporting the issue!

For clarity, do you get the same issue with the invest or calibrate functions, or are you only using plotFit?

Hi Tanya. I cannot seem to reproduce your issue with render(). Could you kindly provide a minimal reproducible example?

Hi Brandon,

I think I found the problem and it isn't because of plotFit. That was just
a coincidence. I wrapped rmarkdown::render() in another function:

wiki.render <- function (start.dir, src.dir, head.txt, src.file, in.file) {

Get text inputs for main file

x <- readLines(file.path(start.dir, head.txt), warn = F)
y <- readLines(file.path(src.dir, src.file))
# Write text inputs to main file
write(x, file = file.path(start.dir, in.file))
write(y, file = file.path(start.dir, in.file), append = TRUE, sep =

"\n\n")
# knit/render (output details specified in *Head.txt)
render(file.path(start.dir, in.file))
# Clean up
file.remove(c(file.path(start.dir, in.file)))
}

(I used plotFit in the scr.file.) The problem only happens when I use my
wiki.render function and not when I use render() on its own. render() has
an argument, envir = parent.frame(), and I probably need something other
than the default value.

Sorry to trouble you!

Best regards,
Tanya

On 27 July 2014 20:04, Brandon Greenwell notifications@github.com wrote:

Hi Tanya. I cannot seem to reproduce your issue with render(). Could you
kindly provide a minimal reproducible example?


Reply to this email directly or view it on GitHub
#4 (comment).

No trouble at all. Thank you for the report.