The R Project SVN R

Rev

Rev 4562 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4562 Rev 4580
1
#!/bin/sh
1
#!/bin/sh
2
##--- NEW: ----------
2
##--- NEW: ----------
3
##
3
##
4
## Given a list of files of the form    .../.../<name>.R,
4
## Given a list of files of the form    .../.../<name>.R,
5
##
5
##
6
## Produce one large file, i.e. write to  stdout
6
## Produce one large file, i.e. write to  stdout
7
##  'cat'ting the files together with
7
##  'cat'ting the files together with
8
##  1) Putting   a HEADER in front
8
##  1) Putting   a HEADER in front
9
##  2) Wrapping every file in order to be more order independent
9
##  2) Wrapping every file in order to be more order independent
10
##  3) appending a FOOTER ...
10
##  3) appending a FOOTER ...
11
 
11
 
12
## Should work WHEREVER this is called from :
12
## Should work WHEREVER this is called from :
13
(cd `dirname $0`/..
13
(cd `dirname $0`/..
14
 RHOME=`pwd`; export RHOME
14
 R_HOME=`pwd`; export R_HOME
15
)
15
)
16
RHOME=`cd ${RHOME}; pwd`	# absolute
16
R_HOME=`cd ${R_HOME}; pwd`	# absolute
17
 
17
 
18
PKG=$1; shift;
18
PKG=$1; shift;
19
FILES="$@"
19
FILES="$@"
20
 
20
 
21
#Dbg> echo "RHOME=$RHOME"; echo
21
#Dbg> echo "R_HOME=$R_HOME"; echo
22
#Dbg> echo "FILES=$FILES"; echo ; echo; exit
22
#Dbg> echo "FILES=$FILES"; echo ; echo; exit
23
 
23
 
24
## 1) ---- Header ----
24
## 1) ---- Header ----
25
(cat <<_EOF_
25
(cat <<_EOF_
26
.ptime <- proc.time()
26
.ptime <- proc.time()
27
postscript('PKG-Examples.ps')
27
postscript('PKG-Examples.ps')
28
.par.postscript <- par(no.readonly = TRUE)
28
.par.postscript <- par(no.readonly = TRUE)
29
options(contrasts = c(unordered = "contr.treatment", ordered =  "contr.poly"))
29
options(contrasts = c(unordered = "contr.treatment", ordered =  "contr.poly"))
30
_EOF_
30
_EOF_
31
) | sed "s/PKG/${PKG}/"
31
) | sed "s/PKG/${PKG}/"
32
if [ "$PKG" != "base" ]; then echo "library('$PKG')" ; fi
32
if [ "$PKG" != "base" ]; then echo "library('$PKG')" ; fi
33
 
33
 
34
## 2) ---- edit a few of these files:
34
## 2) ---- edit a few of these files:
35
for file in $FILES
35
for file in $FILES
36
do
36
do
37
 bf=`basename $file .R`
37
 bf=`basename $file .R`
38
 if [ -n "`grep '_ Examples _' $file`" ]
38
 if [ -n "`grep '_ Examples _' $file`" ]
39
 then
39
 then
40
    echo '.Random.seed <- c(0,rep(7654,3)); rm(list = ls())'
40
    echo '.Random.seed <- c(0,rep(7654,3)); rm(list = ls())'
41
 else
41
 else
42
    if [ "$USER" = maechler ];then
42
    if [ "$USER" = maechler ];then
43
	## Remind certain people to upgrade the online help
43
	## Remind certain people to upgrade the online help
44
	echo "'$bf' has no Examples.." >& 2
44
	echo "'$bf' has no Examples.." >& 2
45
    fi
45
    fi
46
 fi
46
 fi
47
 
47
 
48
 cat $file
48
 cat $file
49
 
49
 
50
 if [ -n "`grep 'par(' $file`" ];then
50
 if [ -n "`grep 'par(' $file`" ];then
51
    ## if there were 'par(..)' calls, now reset them:
51
    ## if there were 'par(..)' calls, now reset them:
52
    echo 'par(.par.postscript)'
52
    echo 'par(.par.postscript)'
53
 fi
53
 fi
54
 if [ -n "`grep 'options(contrasts' $file`" ];then
54
 if [ -n "`grep 'options(contrasts' $file`" ];then
55
    ## if contrasts were set, now reset them:
55
    ## if contrasts were set, now reset them:
56
    echo 'options(contrasts = c(unordered = "contr.treatment", ordered =  "contr.poly"))'
56
    echo 'options(contrasts = c(unordered = "contr.treatment", ordered =  "contr.poly"))'
57
 fi
57
 fi
58
done
58
done
59
## 3) ---- Footer ----
59
## 3) ---- Footer ----
60
cat <<_EOF_
60
cat <<_EOF_
61
cat("Time elapsed: ", proc.time() - .ptime,"\n")
61
cat("Time elapsed: ", proc.time() - .ptime,"\n")
62
dev.off(); quit('no')
62
dev.off(); quit('no')
63
_EOF_
63
_EOF_