batchfiles contains batch and GUI files for installing and maintaing R.  

NEWS.  See NEWS file.

INSTALLATIION

To install these utilities, just copy all the .bat and .hta
files in this distribution to any directory in your PATH.
(The Windows console command

   path

isused without arguments will display your path.)

FILES

0. runR.bat.  If this file is copied to myfile.bat then running 
myfile (possibly with arguments) will run myfile.R with those same
arguments.

1. R.bat, Rcmd.bat, Rscript.bat, Rgui.bat, Rscript.bat, JGR.bat - are 
front ends to  the corresponding .exe files.  Running any of these causes the
corresponding R command in your current version of R (automatically
located via the registry) to be run.  Because of the automatic
location of R it means that the user does not  have to update anything 
associated with these commands each time a new version of R is installed.  
Also you can put Rgui.bat on your desktop, associate a Windows 
ShortCut key with it (see http://support.microsoft.com/kb/310417) and 
not have to redo this on each install of a new version of R.  They have the
same syntax as the corresponding .exe files in R, e.g.

	Rcmd INSTALL mypackage -l library
	Rcmd check mypackage 
	Rcmd build mypackage
	Rcmd build mypackage --binary
	Rscript myprog.R < mydata.dat

Also #Rscript.bat is provided which can be used as the first line
of an R script to make it callable as a batch file.  It
should look like this:

#Rscript %0 %*
...R code goes here...

and should be named with .bat extension. See the Rtidy.bat file
for an example.  Note that it does have the disadvantage that
the output of the R program starts off with the command itself.
R needs to be able to handle the perl/python/ruby -x switch.
In the meantime #Rscript.bat will mainly be useful for those
scripts where the output does not go to the standard output
or where the addition of this line is acceptable.

2. Rversions.hta - GUI lists all versions of R on your
system  and allows you to choose one as your default,
setting the  registry appropriately.  Just run without
arguments, .e.g.  
	Rversions.hta 
For example, suppose we want to check a package using two
different versions of R.  Then run 

	Rcmd check mypkg

	:: in next command set different version of R
	Rversions.hta 
	Rcmd check mypkg

	:: in next command reset to original version of R
	Rversions.hta 

3. Rversions.bat - similar to Rversions.hta but batch rather
than GUI.  Run without arguments to list the versions
available.  Run  with a single argument equal to one of the
lines listed to  set a new version.  e.g.  

	:: list R versions
	reversions.bat

	:: check mypkg using R current version, 2.4.0, say
	Rcmd check mypkg

	:: switch to version R-2.5.0 and recheck
	rversions R-2.5.0
	Rcmd check mypkg

	:: reset back to version 2.4.0
	rversions.bat R-2.4.0

4. copydir.bat - can be used to copy the libraries from an
old version of R to your new one.  It will not overwrite any
libraries already there so it should be safe to use. e.g. to
upgrade R to a new version

  :: first, download and install R-2.5.0, say
  :: now perform the next two commands at the Windows console
  cd \Program Files\R
  copydir R-2.4.0\library R-2.5.0\library

  :: next command only needed if you have *.site files
  copy R-2.4.0\etc\*.site R-2.5.0\etc

  :: ... now startup new version of R and issue command
  update.packages(checkBuilt = TRUE, ask = "graphics")
  :: or (see note below)
  update.packages(ask = "graphics")

  :: press OK and it will update those packages as necessary
  :: ... exit R and start it up again ...

Note that the checkBuilt=TRUE argument will potentially cause
all your packages to be downloaded again so you could try
leaving it off and then reissue the command with checkBuilt=TRUE
later only if you run into problems.  I normally do it without
the checkBuilt=TRUE.

It is anticipated that this command will ultimately be
superceded by functionality in the R setup procedure at
which time this will be deprecated.  Note that this method
of just copying libraries may not work depending on the
versions of R involved.  If its necessary to re-install most
packages it can be done by issuing the following R command
after performing the copydir.bat:
install.packages(installed.packages()[,1])
 
(Note that 2.8 of the R Windows FAQ

http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f

refers to copying any installed package to the library
folder but does not address how to accomplish that.  That
omission is what copydir.bat addresses.)

5. movedir - same arguments as copydir.  Only difference is
that it moves the directories rather than copy them.  This
can be used if you are no longer interested in maintaining
the old version of R.  This has the advantage that its much
faster than copydir.  The example under copydir works with
movedir too.  Just replace copydir with movedir in that
example.  Comments under copydir.bat apply here too.

6. Rfind.bat - will search system for various tools needed
to make R packages.  It also shows where the current R
installation is (R_HOME line).  It does not actually set or
change any environment variables or any other aspect of the
system so it is always safe to run.  It takes no arguments.
e.g. Rfind

7. sweave.bat - will run sweave, then pdflatex and then
display latex file.  Requires Rterm.bat .  e.g.

      sweave mydoc.Rnw
   or
      sweave mydoc 

The script runs sweave, pdflatex and then displays the pdf
file (assuming the user has .pdf extension associated with a
pdf viewer).  If there is an error in sweave or the .tex
file is not newer than the sweaved file the script stops.
Similarly if there is an error in pdflatex or the .pdf is
not newer than the .tex file then the script stops.
Note that _two_ .pdf files are generated.  They are
identical except one has a unique name created by
suffixing the base with the date and time.  The one
with the unique name is the one viewed.  This overcomes
problems of not being able to view the .pdf if the .pdf
from a prior run is current being viewed (which would
happen since the Acrobat viewer won't allow you to view
two files of the same name concurrently).  Every so often
the user should delete all *.bck.pdf files.

Try:

sweave

without arguments to see options and get more info.

8. withgs.bat - temporarily adds ghostscript to your
path (finding its path in the registry) and runs the 
command given as an argument.  For example, to use the
fig2dev command to create a tiff file from a fig file
try this:

 withgs fig2dev -L tiff myfile.fig > myfile.tiff

9. find-miktex.bat - this is run without arguments to list
the MiKTeX folders as found in the Windows registry.

10. makepkg.bat.  This is only needed by users who build
their own packages and make use of the .Rbuildignore
facility. It will automatically run a build followed by
check or install so that files listed in the .Rbuildignore
file are not checked or installed.  The first argument is
install or check and the second argument is the package
name.  If the package is called mypackage then the current
directory should have a mypackage and a library folder in
it.  e.g.

	makepkg check mypackage
	makepkg install mypackage

You can set flags in the first few lines of the batch file.
Users may wish to use svn to maintain versions of their 
source packages in which case the .Rbuildignore facility
is less important in which case this command would not
be needed either.

DEPRECATED AND CHANGED

Some functionality in older versions of batchfiles has been
deprecated or eliminated:

- miktex-refresh.bat is no longer needed as of R 2.2.0

- the batch files no longer look for ...\R\library or look for ...\R\*.site.  

ADDITIONAL FILES

1. RESOURCES - additional information on writing Windows XP batch files.

2. COPYRIGHT and COPYING - this is free software subject to the GPL license as described.

3. THANKS - acknowledgments.

