new r script functions, made some small changes in sweave, hope to put lumis version and mine together