Skip to content

build CONTENTS or 00Index.html without installing whole package

5 messages · Jonathan Baron

#
To maintain my R site, I'm trying to install html help files only, but
also keep track of the version (with DESCRIPTION).  I have the
following bash script, which works except for 00Index.html.  That is
not a huge problem because the help files are still searchable, but
I'd like to fix it.

A long time ago I asked the same question, and Brian Ripley said to
use --index as an option to build-help.pl, but that isn't an option
anymore.  It seems that the 00Index.html file is built from the
CONTENTS file, but I can't find how to construct that either.  Here's
the script so far.  It works pretty much.  (I'm not sure what happens
if the pdf vignettes don't exist already: so far they have all existed
and it works for those.  And the last line doesn't work, so I just
install a package and then the indices get rebuilt.)

#!/bin/bash
# makes indexable help files for R packages, including pdf vignettes
# usage inst.bat "[files]"
  for PKG in `ls $1`
    do
      echo $PKG
      tar xfz $PKG
      PK=`echo $PKG | /bin/sed -e 's/.tar.gz//' | cut -d"_" -f1`
      echo $PK
      mkdir -pv /usr/lib/R/library/$PK
      mkdir -pv /usr/lib/R/library/$PK/html
# copy description (which contains version number) and CONTENTS (for index)
      cp $PK/DESCRIPTION /usr/lib/R/library/$PK
# build and move vignettes if present
      if [ -d $PK/inst/doc ]; then
       mkdir -pv /usr/lib/R/library/$PK/doc
        R CMD buildVignettes\($PK,$PK\)
        cp $PK/inst/doc/* /usr/lib/R/library/$PK/doc
      fi
# make html files
      R CMD perl /usr/share/R/perl/build-help.pl --html /home/baron/$PK /usr/lib/R/library
      rm -rf $PK
    done
# rebuild indices (doesn't work)
R CMD make.packages.html
#
Replying to my own message, I've now fixed up the bash script so that
it works (below).  I don't think that buildVignettes does anything I
need, so I commented it out (but now runs).  Rscript, and not R CMD
(which I was mistakenly using before), seems to be the way to run
arbitrary R functions from a script like this, although R CMD works
for the perl script.

But the main problem remains.  Still no 00Index.html filles or
CONTENTS.  I suppose I could write a script to generate the
00Index.html file from the Rd files, but I'm sure I'd be reinventing
the wheel.

Reminder: The main purpose of this is to set up a site with all the
help files of all the packages available in html format, and pdf files
of vignettes.  Once I figure this out, it will be much easier for
someone else to reproduce the site I have at
http://finzi.psych.upenn.edu, and easier for me to maintain it.

#!/bin/bash
# makes indexable help files for R packages, including pdf vignettes
# usage inst.bat "[files]" (in quotes, if wildcards)
for PKG in `ls $1`
  do
    tar xfz $PKG
    PK=`echo $PKG | /bin/sed -e 's/.tar.gz//' | cut -d"_" -f1`
    echo $PK
    mkdir -pv /usr/lib/R/library/$PK
    mkdir -pv /usr/lib/R/library/$PK/html
# copy description (which contains version number)
    cp $PK/DESCRIPTION /usr/lib/R/library/$PK
# move vignettes if present
    if [ -d $PK/inst/doc ]; then
      mkdir -pv /usr/lib/R/library/$PK/doc
      cp $PK/inst/doc/* /usr/lib/R/library/$PK/doc
#      Rscript --default-packages="tools" --no-init-file --no-save \
#        -e "buildVignettes('$PK','/usr/lib/R/library/$PK')"
    fi
# make html files
    R CMD perl /usr/share/R/perl/build-help.pl --html \
      /home/baron/$PK /usr/lib/R/library
    rm -rf $PK
  done
Rscript --no-init-file --no-save -e "make.packages.html()"
4 days later
#
Replying to myself again, I've now figured out how to build all the
help files, including 00Index.html, without actually building the
package.  The point is to construct a complete list of all html help
files for searching.

The one thing I cannot figure out is how to build the index of all
packages which (for me) is at
/usr/share/doc/R-2.9.0/html/packages.html
Apparently this requires something other than DESCRIPTION and
00Index.html files in each package, which is all I have.

Here is the script:

#!/bin/bash
# makes indexable help files for R packages, including pdf vignettes
# usage inst.bat "[files]" --- quotes needed for wildcards like "*.tar.gz"
for PKG in `ls $1`
  do
    tar xfz $PKG
    PK=`echo $PKG | /bin/sed -e 's/.tar.gz//' | cut -d"_" -f1`
    echo $PK
    mkdir -pv /usr/lib/R/library/$PK
    mkdir -pv /usr/lib/R/library/$PK/html
# copy description (which contains version number)
    cp $PK/DESCRIPTION /usr/lib/R/library/$PK
# move vignettes if present
    if [ -d $PK/inst/doc ]; then
      mkdir -pv /usr/lib/R/library/$PK/doc
      cp $PK/inst/doc/* /usr/lib/R/library/$PK/doc
    fi
# make html files
    R CMD perl /usr/share/R/perl/build-help.pl --html /home/baron/$PK /usr/lib/R/library/
# make indices
    Rscript --vanilla -e "tools:::.writePkgIndices('$PK','/usr/lib/R/library/$PK')"
    rm -rf $PK
  done
# try to build package list, doesn't work
# Rscript --no-init-file --no-save -e "make.packages.html(packages=FALSE)"
#
OK, one more for the records.  This script is now written so that it
uses Rscript instead of bash.  The last line still does not work.  I
don't know what make.packages.html requires, but apparently it
requires more than DESCRIPTION and 00Index.html in order to include a
package.  (The line about buildVignettes seems useless, so I commented
it out.)  The command line can include *.  So I use this after
download.packages(), with inst.R *.tar.gz.  (inst.R is what i call the
script.)

#!/usr/bin/Rscript --vanilla
# makes indexable help files for R packages, including pdf vignettes
# usage inst.R [files]
FILES <- commandArgs(TRUE)
print(FILES)
for (PKG in FILES)
  {
    system(paste("tar xfz",PKG))
    PK <- strsplit(PKG,"_")[[1]][1]
    print(PK)
    system(paste("mkdir -pv /usr/lib/R/library/",PK,"/html",sep=""))
# copy description (which contains version number)
    system(paste("cp ",PK,"/DESCRIPTION /usr/lib/R/library/",PK,sep=""))
# move vignettes if present
    system(paste("cp -r ",PK,"/inst/doc /usr/lib/R/library/",PK," >& /dev/null",sep=""))
#    buildVignettes(PK,paste("/usr/lib/R/library/",PK,sep=""))
# make html files
    system(paste("cd /usr/share/R/perl; ","perl build-help.pl --html /home/baron/",
                 PK," /usr/lib/R/library/","; cd /home/baron",sep=""))
# make indices
    tools:::.writePkgIndices(PK,paste("/usr/lib/R/library/",PK,sep=""))
    system(paste("rm -rf",PK))
  }
# try to build package list, doesn't work
# make.packages.html()