s-news
[Top] [All Lists]

[S] Variations on literate programming

To: s-news <s-news@wubios.wustl.edu>
Subject: [S] Variations on literate programming
From: Frank E Harrell Jr <fharrell@virginia.edu>
Date: Thu, 24 Feb 2000 10:51:41 -0800
Organization: University of Virginia
Sender: owner-s-news@wubios.wustl.edu
Literate programming, in which programs are embedded in full documentation 
(LaTeX, html,
etc.) and extractors pull out either the code (to run through a compiler) or 
text markup,
seems to have a lot of advantages.  I am interested in a different angle in 
which
S-Plus programs do computations that are inserted into documents.  As I see it,
literate programming utilities do not allow for program output to be 
incorporated semi-
automatically into the document.

Here is a simple
LaTeX example where S-Plus calculates a chi-square statistic and a P-value for 
inserting
into a table.  Here I assume that LaTeX variables are named the same as S-Plus 
variables,
and the names contain only letters, so that code can be simplified using a 
little function.
This function can also convert NAs to blanks.

lvar <- function(x, digits=2)
 paste('\\def\\',substitute(x),'{',
          ifelse(is.na(x),'',round(x,digits)),'}', sep='')

cat(lvar(chisq), lvar(pval,4), sep='\n', file='parms.tex')

The contents of parms.tex will look like the following:

\def\chisq{3.84}
\def\pval{0.05}

Inside the main LaTeX source use:

\input{parms}
\begin{tabular}{l|cc} \hline\hline
Test          & $\chi^2$ & $P$--value \\ \hline
Age effect & \chisq & \pval \\ \hline
\end{tabular}

Has anyone seen are more systematic and general approach to this
sort of problem?  I would especially like for statistical reports to
have calculated values inserted (as above) but also able to link
better with the code that generated the calculations, so the report
can be somewhat self-documenting and easier to maintain over time.

--
Frank E Harrell Jr
Professor of Biostatistics and Statistics
Division of Biostatistics and Epidemiology
Department of Health Evaluation Sciences
University of Virginia School of Medicine
http://hesweb1.med.virginia.edu/biostat


-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>