What's new? | Help | Directory | Sign in
Google
batchfiles
Windows batchfiles for use with R
  
    
Code License: GNU General Public License v2
Labels: R, Windows, batch

batchfiles contains batch (.bat) and javascript (.hta and .js) files useful in conjuction with R and R packages on Microsoft Windows. There is no formal installation, each consists of a single file and they are all independent of each other so just place all of them or any subset of them anywhere in your path and you can immediately access them from any console session. For Vista use the latest version of batchfiles. Although all testing is now only done on Vista many of them will likely work on XP too. (Version 0.3-2 of the batchfiles and prior were only tested on XP.) The batchfiles are available from CRAN, i.e. the R archives, and the development version is available from the Source tab above which provides for browsing, svn access and downloads of individual files through your browser.

NEWS

In addition to the news listed here there is a NEWS file in the package with additional news. Also there is a README file in the package with documentation and a RESOURCES file in the package with additional information on Windows batch files, in general.

July 18/08. This message on r-devel discusses a number of reasons not to set PATH yourself but, instead, use batch files.

July 10/08. New file, show-svn-info.hta added. When run from a Tortoise SVN folder (version 1.5 or higher) it shows some information about it.

July 5/08. batchfiles 0.4-3 is now on CRAN. It fixes a bug in Sweave.bat and Stangle.bat .

June 25/08. Came across (1) this presentation by Andrej Blejec (in Slovenian), (2) this Sweave guide by Ista Zahn on the TeX User Group site and (3) these Lyx support files in the CRAN Other Software section that mention Sweave.bat .

June 23/08. As toggleDoc was the only perl program in batchfiles it has been removed from the development source to maintain the integrity of the collection. After batchfiles 0.4-2 it will no longer be distributed with batchfiles; however, it can still be found in batchfiles_0.4-2.zip as it and all past versions of batchfiles are archived on CRAN.

June 15/08. batchfiles_0.4-2.zip has been uploaded to CRAN. Details in ANNOUNCE and README.

June 13/08. Stangle.bat and Sweave.bat have been made to be the same file. Each queries the name it was called by to determine which to run.

June 9/08. Stangle.bat added. Like Sweave.bat (version 0.3-2 and later), Stangle.bat does not depend on rtools/cygwin/sh.exe .

June 9/08. sweave.bat is now Sweave.bat in the svn. This should not make any difference as Windows is case insensitive to file names.

May 20/08. New facility in the development Source in which the various batchfiles first search for rbatchfilesrc.bat in current directory and then in %userprofile% and then in same directory as the batchfile itself and use first one found, if any. If one is found then it may contain set statements for R_HOME, R_TOOLS and R_MIKTEX (or a subset of those) and it will use those in place of the registry and its MiKTeX heuristic. That will allow use of batchfiles without setting any environment variables outside of the batchfiles and without registry access. It also allows different directories to easily and automatically use different versions of R. More info is available in the NEWS file. It is anticipated that most users will not use this facility nor the closely related environment variable facility since its easier just to let the batchfiles automatically determine the various paths by allowing it to access the registry but for some users who wish to set up certain custom installations this may be a useful alternative. Note that if one does not use this facility or the environment variables provided then the registry is only read, not written with one exception: That one exception is Rversions.hta (and in batchfiles 0.3-2 also rversions.bat) which can set in the registry which version of R is the current one. It does that by calling RSetReg.exe which is a program that is included with every version of R.

May 19/08. Added a new question to the Troubleshooting Section below.

May 15/08. Added a workaround for a bug in R in which Sweave.sty is not found when sweaving a file.

Mar 5/08. Added a Troubleshooting section below.

May 4/08. batchfiles 0.4-1 has been uploaded to CRAN. It eliminates the need to set the PATH when building R packaes -- previous versions of batchfiles eliminated it only for running R but not building packages. Also new rtools.bat and el.js utilities. Details in NEWS, ANNOUNCE and README.

Apr 30/08. The development source for Rcmd.bat and similar batch files now automatically find rtools in the registry (and they look for MiKTeX heuristically in a few places) so not only does one not have to set the PATH variable for running R but one does not have to set it for building R packages either.

Apr 30/08. The XP HowTo's are being moved from the box to the right to their own section on this page below. A new one on a free utility, SetEnv, is added too.

Mar 20/08. Added two new Vista HowTo's. The Vista HowTo's are now below in the HowTo section while the XP HowTo's (some of which apply to Vista too) are in the Links box to the right.

Jan 16/08. batchfiles version 0.4-0 is now on CRAN. (Version 0.4-0 and all future versions will be tested on Vista. Reports from XP users using it are welcome. Version 0.3-2 was tested on XP so XP users can use that.)

Jan 12/08. sweave.bat has been made independent of Rterm.bat so now all batch and javascript files are standalone and do not depend on each other or on other external programs other than possibly R in some cases. (toggleDoc.pl that was just contributed does depend on perl and on toggleDoc.js so it is the only utility with non-R dependencies.)

Jan 12/08. Removed find-miktex.bat, Rfind.bat, makepkg.bat and withgs.bat from the development Source -- they are still available in batchfiles version 0.3-2.

Jan 12/08. Added toggleDoc.pl/toggleDoc.js, a perl program and associated file, that adds a toggle box to the 00Index.html file in each package in your library. When the toggle box is checked, it collapses similar HTML help lines into one. Try checking and unchecking the toggle box labeled Show All at this page to get the idea. Contributed by Dieter Menne.

Jan 2/08. There is a new file, RguiStart.bat, in the development Source that starts up Rgui.exe in the directory specified by its first argument. On Vista put RGuiStart.bat in the %APPDATA%\Microsoft\Windows\SendTo folder and then in Windows Explorer you can right click any folder > SendTo > RGuiStart.bat to start R in that folder. See comments in these r-help posts: https://stat.ethz.ch/pipermail/r-help/2008-January/149455.html and https://stat.ethz.ch/pipermail/r-help/2008-January/149458.html RGuiStart.bat is actually the same file as Rgui.bat, Rcmd.bat, R.bat, Rterm.bat, Rscript.bat, #Rscript.bat and Rjgr.bat. The common script queries what name it was called by to determine what to do.

Sep 9/07. In the development version of batchfiles there is a new Rversions.hta for Vista with some code cleanup and improved heuristic for locating R.

DOWNLOAD

Get the latest release from CRAN or the development source from the Source tab above. Version 0.4-0 and later have been tested on Vista only while version 0.3-2 and prior were tested on XP only.

TROUBLESHOOTING

Q1. Rcmd.bat and similar batch files do not find the rtools.

A1. Make sure you have the most recent version of rtools. Registry support was added to rtools in April or May of 2008 so with older versions of the rtools, the rtools may not be automatically located.

Q2. Rcmd BATCH does not work.

A2. In very old versions of R (prior to R 2.5.1) Rcmd.exe BATCH (which is, in turn, used by Rcmd.bat in batchfiles) had problems with pathnames with embedded spaces. If you are still using an R version that old its time to upgrade!

Q3. When running sweave.bat the Sweave.sty file is not found.

A3. This is a known problem in R that will likely be fixed in an upcoming version of R. Put sweave.sty in the same directory as your Rnw file (or other place where MiKTeX can find it) and put this line in your .Rnw file: \usepackage{Sweave}

Q4. I understand that Rcmd.bat and the other tools look in the Windows registry to find R and the Rtools. Can I use Rcmd.bat and the others if I cannot or wish not to modify the registry?

A4. There are two alternatives to using the registry:

1. Set R_HOME, R_TOOLS and R_MIKTEX environment variables. In that case Rcmd.bat and the other tools will use the indicated paths rather than look in the registry. For example, do the following (or to do it permanently set the paths via the control panel or via the free Redmond Path utility):

set R_HOME=C:\Program Files\R\R-2.7.0
set R_TOOLS=C:\Rtools
set R_MIKTEX=C:\Program Files\MikTex 2.7\miktex\bin

(Note that MiKTeX is found via a heuristic, not the registry, so if you have placed MiKTeX in the usual place then you may not need to set R_MIKTEX.)

2. The other alternative is to create a file called rbatchfilesrc.bat that contains the three lines above or similar lines and place that file in the current directory, in %userprofile% or in the same directory as Rcmd.bat and other tools in which case it will search for it in the given order and temporarily set the environment variables as indicated but only while Rcmd.bat or other file from batchfiles is running.

HOWTO

XP HOWTO

XP HowTo's are in the Links box to the above right. Some of these apply to Vista too. HowTo's specific to Vista follow in the next section after this one.

Set Environment Variables Permanently through batch. SetEnv

VISTA HOWTO

Install package from CRAN. On your desktop, right click on R and choose Run As Administaror . Then when R starts choose the Packages | Install Package(s) menu item. Alternately, from the Windows command line use the elevation and Rgui batchfiles, el.js and Rgui.bat, to start R as shown below and then proceed to Packages menu, as before:

el Rgui

Note that if despite doing the above that you get a message about packages.html not being writable find that file in Windows Explorer and right-click it > Properties > Security tab and reset the permissions appropriately. You may or may not also need to do the same thing on its folder.

Disable Vista Sidebar Disabling the Vista sidebar will improve the performance of your system slightly.

Determine whether you are running SP1 of Vista or not. When reading this note that the original Vista is referred to by Microsoft as Build 6000 whereas the SP1 release is called Build 6001.

Changing PATH. The PATH command from the Windows console will change the PATH for that session (PATH /? for more info). To permanently change the path (1) these instructions describe how to do it through the control panel or (2) one can use the setx command from the Windows resource kit (however it does not come with Windows and costs extra) or (3) the free Redmond Path utility makes it particularly easy by providing a gui editor into which it dumps you path, one component per line, so you can visually edit it and save it back. This PATH info all applies to XP as well. Of course if you use the batchfiles here you will likely never have to change your path in the first place.

VISTA HACKS

These HowTo's are termed hacks since they are not recommended but are provided for the curious or frustrated.

Vista introduced the User Account Control (UAC) feature that essentially lets you run as a least authorized user rather than essentially as an Administrator the way you had to run in XP. This improves security but every so often you will get prompts asking you to elevate your level for a certain task. If you have upgraded to Vista SP1 then you won't get quite as many. Some people have described this as frustrating; however, for most people, in fact, it probably will not occur more than a few times a day. At any rate at the risk of compreomising the security of your system, its possible to disable or partially disable UAC. (Note that UAC problems should not be confused with file permission problems. For file permission problems right click the file in Windows Explorer and choose Properties and then the Security tab and adjust the settings appropriately.)

UAC. For the best security leave UAC alone but it but if you feel you must disable or partially disable it then this article by Scott Lowe explains your options. These including turning it on and off via msconfig, the control panel, the registry or group policy, disabling prompts without disabling UAC entirely and running selected applications at Administrative level. Also see this article on how to disable UAC, this information on tweakUAC which makes it easy to turn UAC on and off and to run it in Quiet mode which eliminates prompts but only when you are running as Adminstrator. Also this link shows a 12 step procedure to Disable UAC for certain apps only using Microsoft's free Compatability Toolkit. Also see explanation by Greg Schultz. Another article on making UAC less annoying can be found at HowToGeek.

Cleaning up after installing Vista SP1 Vista lets you revert back from SP1 so it leaves the original files in place. If you are really sure you won't want to revert then here is how to remove those original files from your system.