4

I'm trying to write a Bash script in Ubuntu 10.04 that opens a Python file which exports a CSV, and then runs the following Rscript with the goal of exporting a HTML with plots from Dashboard.Rmd:

require(knitr)
setwd('/home/sensors/Desktop/')
knit2html('Dashboard.Rmd')
browseURL('Dashboard.html')

Dashboard.Rmd is an R markdown that calls read.csv on the csv from the first step, makes a data frame and creates plots, but that part's working fine. According to this, I figure that Rscript should replicate the action of pressing "Knit HTML" in R Studio. However, the html it creates is identical to the last time Knit HTML was pressed; i.e. even if the CSV is different, the html doesn't reflect the change.

I also tried using a separate line for knit and markdownToHTML with the same effect. It seems like it doesn't source the code from the Rmd when performing knit. It does update the html properly when I enter the commands from that Rscript into the console of R Studio with Dashboard.Rmd open. However I'm not sure how to translate that into a Bash script. I also tried knit2html with envir=new.env(), envir=R_GlobalEnv, and envir=parent.frame() with no luck. Any help would be appreciated!

Community
  • 1
  • 1
  • 1
    Did you turn on cache? (`cache=TRUE`) You'd better let us know what is inside `Dashboard.Rmd`, or give a minimal reproducible example. BTW, I recommend you to `setwd('/home/sensors/Desktop/')` before `knit2html('Dashboard.Rmd')` (you do not need to specify the `output` argument). Absolute paths are bad in general. – Yihui Xie Jun 30 '12 at 17:17
  • 1
    It actually worked when I set cache=FALSE in the code chunk. I'm relatively new to programming so I didn't know not to use absolute paths, but I'll keep that in mind. Thanks so much! – Alex Kiefer Jul 02 '12 at 15:01
  • That is fine. I edited your code to make it simpler. – Yihui Xie Jul 02 '12 at 15:35

1 Answers1

2

So it turns out that this was an artifact of cache=TRUE -- the HTML file was not changed because everything was cached.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419