this is my first ever post and i am quite new to all of this, so i hope i am doing this right. my problem is the following: i wrote some R code to get some ID's from a Database, which are then used to brew templates. the template uses Knitr R to then build some querys around the ID's to get the data then used for the actual report.
the Script goes like this:
...
create.report() <- function(ID){
reportname <- "MyReport.Rnw"
brew('template.rnw',reportname)
knit(reportname)
....
}
the template.rnw with knitr gets the ID passed by brew :
\section*{This is a Report for <%=ID%>}
<<loaddata, echo =FALSE>>=
query <- paste0("SELECT ... WHERE ID= ",<%=ID%>) # this gets us the Data for the report
data <- dbGetQuery(con,query) # Data from db is in Data now.
@
...
And this just worked fine for me. But now i want to pass more parameters from the Script to the template then just simple Input like an ID. For example i would like to pass a timespan like from="2010-01-01" ,to="2012-01-01"
to maby use this like
...
create.report() <- function(ID,fromdate,todate){
reportname <- "MyReport.Rnw"
brew('template.rnw',reportname)
knit(reportname)
....
}
.rnw template
<<loaddata, echo =FALSE>>=
from <- paste0("AND date(...) =>'",<%=fromdate%,"'")
to <- paste0("AND date(...) =< '", <%=todate%>,"'")
query <- paste0("SELECT ... WHERE ID= ",<%=ID%>,from,to) # this gets us the Data
data <- dbGetQuery(con,query) # Data from db is in Data now.
@
...
but the Problem with that is, that he wont leave the fromdate and todate to be a string like "2010-01-01" and allways make it 2008.
is there any way to tell the Code Chunks not to do anything with the brew input before setting it, or maby pass the parameters from outside to the chunk so they dont have to be set in the chunk ?
I hope you can help me with this, or show me a proper way around it.