USGS-R / hypeRusgs

Creating some R hype by showing off advanced techniques applied to USGS science.
3 stars 5 forks source link

Capturing the contents of a script and writing it to a text file #21

Closed pestack closed 5 years ago

pestack commented 5 years ago

I use a "master" script to run boosted regression models. For different runs I edit the script to alter which input data set I'm reading in or I might make changes to which variables I'm including in the model (by commenting on or off certain lines of code). To help organize my results I create a separate directory for each model run using: mainDir <- "pathName" subDir <- "directoryName"

dir.create <- (file.path(mainDir, subDir)) setwd(file.path(mainDir, subDir))

All of the model objects and various graphics are written to the directory I've created but in order to understand the specifics of the model run I would like to capture the contents of the script and write it to a text file in that directory. I've been doing this manually using "save as" but I'd prefer to do this with code at the end of the script so that it happens automatically. Is there a way to do this? I've fiddled around with knitr but haven't been able to get it to work.