syntax highlighting while rendering SQL using knitr

Issue knitr will execute SQL code using engine=’mysql’ but not highlight syntax: \documentclass{article} \begin{document} <<engine=’mysql’, engine.opts=”-h localhost”>>= SHOW DATABASES; @ \end{document} On the other hand using engine=’highlight’ will highlight the code but not execute it. \documentclass{article} \begin{document} <<engine=’highlight’, engine.opts=’-S sql

Continue reading

Sweave syntax highlighting in output – revisit

Issue My question is the same as the one in the link Sweave syntax highlighting in output. I have followed the suggestion by daroczig https://tex.stackexchange.com/questions/5113/how-to-colorize-syntax-using-r-sweave, and created the following test.Rnw file: \documentclass{article} \RequirePackage{fancyvrb} \RequirePackage{listings} \SweaveOpts{keep.source=TRUE} <<SweaveListingsPreparations, results=tex, echo=FALSE, strip.white=false>>= require(SweaveListingUtils)

Continue reading

Error in for loop in ELO rating algorithm

Issue I’m trying to run the ELO rating code from here https://github.com/xsankar/hairy-octo-hipster/blob/master/ELO-538.R The dataset I’m using is here https://www.mediafire.com/file/0a5v393ki775vw9/sport2.xlsx/file The code I’m running is slightly modificated, I’m working with only 17 weeks instead of 22 as in the original code,

Continue reading

Model fitting functions and environemnts

Issue Here is a kind of minimal example for a problem I stumbled upon: mylm <- function(formula,data,subset=NULL){ mysubset <- subset # some other clever manipulation lm(formula,data,mysubset) } mydata <- data.frame(x=rnorm(10),y=rnorm(10)) mylm(y~x,mydata) # this fails! The reason why the last line

Continue reading

Environments in R Shiny

Issue At http://shiny.rstudio.com/articles/scoping.html the rules for scoping in shiny are well explained. There are 3 environments or levels nested inside each other: objects available within a function, within a session and within all sessions. Using <- will change the object

Continue reading

R shiny object scoping

Issue I’m trying to access an object(a<-get(obj1,envir=parent.environment())) residing in the calling environment from the called environment myf and I can’t get it working. Error I’m getting is Object obj1 not found. I tried parent.frame()also. Any ideas? library(shiny) shinyApp( ui =

Continue reading

R: Source personal scripts keeping some functions hidden

Issue Follow up to this I want to source scripts inside a given environment, like in sys.source, but “exporting” only some functions and keeping the others private. I created this function: source2=function(script){ ps=paste0(script, “_”) assign(ps, new.env(parent=baseenv())) assign(script, new.env(parent=get(ps))) private=function(f){ fn=deparse(substitute(f))

Continue reading

attach() inside function

Issue I’d like to give a params argument to a function and then attach it so that I can use a instead of params$a everytime I refer to the list element a. run.simulation<-function(model,params){ attach(params) # # Use elements of params

Continue reading