I need to call a database with underscores in table names in an R block in knitr. There are several thousand table names, and changing names will be a huge problem. Sort of:
<<classRun,fig=FALSE,print=FALSE,echo=FALSE>>=
getdat = function(nbr1,nbr2){
library(RODBC)
database.dsn1<-c("db")
database.user1<-c("username")
database.password1<-c("password")
channel<-odbcConnect(database.dsn1, database.user1, database.password1)
dat = sqlQuery(channel,paste("select * from table_",nbr1,"_",nbr2, sep=""))
}
@
<< results='asis', echo = FALSE>>=
dat = getdat(10,20)
print(dat)
@
I get an error that I am missing $ ("Missing $ insert") due to the underscore in "table_10_20". I played a lot with the addition of "\ $ \" and "\ $ \", you name it. Also played with cat () and paste (), as well as single quotes and double quotes. Any suggestions? Thanks in advance for your help. I start Ubuntu 11.10 and call knitr from RStudio using pdfLaTeX if that matters.
source
share