Last active
August 29, 2015 14:07
Revisions
-
anarosner revised this gist
Nov 25, 2014 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,8 +8,8 @@ setwd("C:/ALR/Models/boo") #example using local windows directory, can easily sw purl( "script1.Rmd", "script1.R" ) #just specify the rmd filename, then r filename, with extensions # you could also specify a directory here (use paste instead of file.path so you can add/change extensions) # I like to keep separate directories for r and rmd, but you don't need to dir <- "C:/ALR/Models/boo" i<-"script2" purl( paste0(dir,"/rmd/",i,".Rmd"), paste0(dir,"/r/",i,".R") ) @@ -24,12 +24,14 @@ purl( paste0(dir,"/rmd/",i,".Rmd"), paste0(dir,"/r/",i,".R") ) #you can purl and write a master/wrapper script all at once, it's really quick wrapper <- "#!/usr/bin/env Rscript" # maybe you want the wrapper script to specify a directory before sourcing files? # wrapper <- rbind( wrapper, # "setwd(\"C:/ALR/Models/boo/r\")" ) for (i in c("script1","script2", "script3") ) { purl( paste0(dir,"/rmd/",i,".Rmd"), paste0(dir,"/r/",i,".R") ) # or simpler version w/o directory info, replace above line with: # purl( paste0(i,".Rmd"), paste0(i,".R") ) wrapper <-rbind(wrapper, paste0("source(\"",i,".R\")")) } -
anarosner revised this gist
Nov 25, 2014 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,8 +23,9 @@ purl( paste0(dir,"/rmd/",i,".Rmd"), paste0(dir,"/r/",i,".R") ) # (i.e. script1.rmd, script2.rmd, etc) #you can purl and write a master/wrapper script all at once, it's really quick wrapper <- "#!/usr/bin/env Rscript" # wrapper <- rbind( wrapper, "setwd(\"C:/ALR/Models/boo/r\")" ) #maybe you want to specify a directory before sourcing files? for (i in c("script1","script2", "script3") ) { purl( paste0(dir,"/rmd/",i,".Rmd"), paste0(dir,"/r/",i,".R") ) -
anarosner created this gist
Oct 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ #purling is in the knitr package library(knitr) setwd("C:/ALR/Models/boo") #example using local windows directory, can easily switch #it can be really simple purl( "script1.Rmd", "script1.R" ) #just specify the rmd filename, then r filename, with extensions # you could also specify a directory here (use paste instead of file.path so you can add extensions) #it's nice to keep r and rmd separate dir <- "C:/ALR/Models/boo" i<-"script2" purl( paste0(dir,"/rmd/",i,".Rmd"), paste0(dir,"/r/",i,".R") ) #if you have multiple scripts you want to run in sequence, # (i.e. script1.rmd, script2.rmd, etc) #you can purl and write a master/wrapper script all at once, it's really quick wrapper <- NULL # wrapper <- "setwd(\"C:/ALR/Models/boo/r\")" #maybe you want to specify a directory before sourcing files? for (i in c("script1","script2", "script3") ) { purl( paste0(dir,"/rmd/",i,".Rmd"), paste0(dir,"/r/",i,".R") ) # (or simpler version w/o directory info) # purl( paste0(i,".Rmd"), paste0(i,".R") ) wrapper <-rbind(wrapper, paste0("source(\"",i,".R\")")) } cat(wrapper) writeLines( text=wrapper, con=file.path(dir,"R","wrapper_script.R" ) ) #now you have a single r script, that can be called/spawned by the server