txtStart {TeachingDemos} | R Documentation |
These functions save a transcript of your commands and their output to a script file, possibly for later processing with the "enscript" program.
They work as a combinations of sink
and history
with a
couple extra bells and whistles.
txtStart(file, commands=TRUE, results=TRUE, append=FALSE, cmdfile, visible.only=TRUE) txtStop() txtComment(txt,cmdtxt) txtSkip(expr) etxtStart(dir = tempfile("etxt"), file = "transcript.txt", commands = TRUE, results = TRUE, append = FALSE, cmdbg = "white", cmdcol = "red", resbg = "white", rescol = "navy", combg = "cyan", comcol = "black", cmdfile, visible.only = TRUE) etxtStop() etxtComment(txt, cmdtxt) etxtSkip(expr) etxtPlot(file=paste(tempfile('plot',R2txt.vars$dir),'.eps',sep=''), width=4, height=4) wdtxtStart(commands=TRUE, results=TRUE, fontsize=9, cmdfile, visible.only=TRUE) wdtxtStop() wdtxtComment(txt,cmdtxt) wdtxtSkip(expr) wdtxtPlot(height=5, width=5, pointsize=10)
dir |
Directory to store transcript file and any graphics file in |
file |
Text file to save transcript in |
commands |
Logical, should the commands be echoed to the transcript file |
results |
Logical, should the results be saved in the transcript file |
append |
Logical, should we append to |
cmdbg |
Background color for command lines in |
cmdcol |
Color of text for command lines in |
resbg |
Background color for results sections in |
rescol |
Text color of results sections in |
combg |
Background color for comments in |
comcol |
Text color of comments in |
cmdfile |
A filename to store commands such that it can be
|
visible.only |
Should non-printed output be included, not currently implemented. |
txt |
Text of a comment to be inserted into |
cmdtxt |
Text of a comment to be inserted into |
expr |
An expression to be executed without being included in
|
width |
Width of plot, passed to |
height |
Height of plot, passed to |
fontsize |
Size of font to use in MSWord |
pointsize |
passed to |
These functions are used to create transcript/command files of your R session. There are 3 sets of functions, those starting with "txt",those starting with "etxt", and those starting with wdtxt. The "txt" functions create a plain text transcript while the "etxt" functions create a text file with extra escapes and commands so that it can be post processed with enscript (an external program) to create a postscript file and can include graphics as well. The postscript file can be converted to pdf or other format file.
The "wdtxt" functions will insert the commands and results into a Microsoft Word document.
If results
is TRUE and commands
is FALSE then the result
is similar to the results of sink
. If commands
is true as well then the results will show both the commands
and results similar to the output on the screen. If both
commands
and results
are FALSE then pretty much
the only thing these functions will accomplish is to waste some
computing time.
If cmdfile
is
specified then an additional file is created with the commands
used (similar to the history
command), this file can be
used with source
or copied and
pasted to the terminal.
The Start functions specify the file/directory to create and
start the transcript, wdtxtStart
will open Word if it is
not already open or create a connection to an open word window.
The prompts are changed to remind you
that the commands/results are being copied to the transcript.
The Stop functions stop the recording and reset the prompts.
The R parser strips comments and does some reformating so the
transcript file may not match exactly with the terminal
output. Use the txtComment
, etxtComment
, or
wdtxtComment
functions to add a comment. This will show up as a line offset
by whitespace in the transcript file, highlighted in the
etxt version, and the default font in Word.
If cmdtxt
is specified then that line
will be inserted into cmdfile
preceeded by a \# so it
will be skipped if sourced or copied.
The tktSkip
, etxtSkip
, and wdtxtSkip
functions will run the
code in expr
but will not include the commands or
results in the transcript file (this can be used for side
computations, or requests for help, etc.).
The etxtPlot
function calls dev.copy2eps
to
create a copy of the current plot and iserts the proper command
into the transcript file so that the eps file will be included
in the final postscript file after processing.
The wdtxtPlot
function calls wdPlot
to send a
copy of the current graph to MS Word.
Most of these commands do not return anything of use. The exceptions are:
etxtStop
returns the name of the transcript file (including the
directory path).
txtSkip
and etxtSkip
return the value of expr
.
These commands do not do any fancy formatting of output, just what you
see in the regular terminal window. If you want more formatted output
then you should look into Sweave
or the R2HTML package.
The MS word functions will insert into the current word document at the location of the cursor. This means that if you look at the document and move the current location to somewhere in the middle (or have another word document open with the location in the middle), when you go back to R, the new transcript will be inserted into the middle of the document. So be careful to position the cursor at the end of the correct document before going back to R.
Do not use these functions in combination with R2HTML or sink
.
Greg Snow, greg.snow@imail.org
sink
, history
,
Sweave
, the odfWeave package, the R2HTML package, the
R2wd package
## Not run: etxtStart() etxtComment('This is todays transcript') date() x <- rnorm(25) summary(x) stem(x) etxtSkip{?hist} hist(x) etxtPlot() Sys.Date() Sys.time() my.file <- etxtStop() # assumes enscript and ps2pdf are on your path system(paste('enscript -e -B -p transcript.ps ', my.file) ) system('ps2pdf transcript.ps') ## End(Not run)