My favorites | Sign in
Project Home Downloads Source
Project Information
Members
Links

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 is independent of the others so just place any or all of them anywhere in your Windows path and you will be able to access them in any Windows console session. A list of the utilities is given below.

The software is downloadable from CRAN (and can also be accessed from the development repository).

Latest News: batchfiles 0.6-6 has been uploaded to CRAN. It is a bug fix release. (Sep/3)

Below on this page are sections on:

PROGRAM LIST

For more information on these commands see the README. Also those marked with (h) after them give help if run without arguments which is an easy way to get info on those. The scripts marked with (0) after them are normally used without arguments so you can just run it that way to see what it does.

Legend:
h = no args gives help
0 = common usage is to enter command name without arguments
d = in development
* = all files marked with one star are the same.  Program checks name by which its called to determine action.
** = all files marked with two stars are the same.  Program checks name by which its called to determine action.

#Rscript.bat - put  #Rscript %0 %*  at top of R script and give it a  .bat  extension to make it a batch file (h) (*)
clip2r.js - pastes clipboard into Rgui.  See comments in file for use from vim. (0)(d)
copydir.bat - copy a library from one version of R to another (h)
el.js - run elevated - Vista and up, e.g. el Rgui  runs R elevated
find-miktex.hta - GUI to find MiKTeX (0)
kopy.bat - copy Rcmd to other batch files (h)(d)
movedir.bat - move library from one version of R to another (h) 
R.bat - like R.exe but finds R from registry (0) (*)
Rcmd.bat - like Rcmd.exe but finds R from registry (*)
Rgui.bat - like Rgui.exe but finds R from registry (0)(*)
RguiStart.bat - like Rgui.bat but arg1 defines folder to start R in (*)
Rscript.bat - run .R script (h) (*)
Rterm.bat - like rterm.exe but finds R from registry (*)
Rtidy.bat - reformat a .R file, e.g. Rtidy myfile.R > outfile.R (d)
Rtools.bat - place Rtools on path for remainder of console session (0)(*)
Rversions.bat - list R and set R version in registry, e.g. on Vista: el cmd/c Rversions R-2.12.0 (0)
RtoolsVersion - display the Rtools version (0)(d)
show-svn-info.hta - show Tortoise svn info if current folder is an svn checkout (0)
Stangle.bat - run arg1 through Stangle. See FAQ Q9 below. (h)(**)
Sweave.bat - run arg1 through Sweave. See FAQ Q9 below. (h)(**)

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 general information on Windows batch files.

Sep 3/11. batchfiles 0.6-6 has been uploaded to CRAN. It is a bug fix release.

May 3/11. Added the cmd package to the downloads area. It has commands cmd32() and cmd64() which will spawn a Windows console session with R's bin\i386 or bin\x64 first in the path. In most cases we recommend users use the batch files here rather than the cmd package.

April 9/11. New batch file RtoolsVersion.bat displays Rtools version.

Jan 30/11. A bug fix version batchfiles_0.6-4.zip has been uploaded to CRAN .

Jan 21/11. A bug fix version batchfiles_0.6-3.zip has been uploaded to CRAN .

Jan 20/11. Added Q9 to Troubleshooting FAQ.

Jan 18/11. A bug in Sweave.bat/Stangle.bat in which it was ignoring switches was fixed. This must have been introduced in some recent version of these scripts since older versions seem not to have this problem. Sweave.bat and Stangle.bat can be obtained from http://batchfiles.googlecode.com/svn/trunk/Sweave.bat and http://batchfiles.googlecode.com/svn/trunk/Stangle.bat

Jan 17/11. A bug in Sweave.bat/Stangle.bat that affected 64 bit systems was fixed. They are in the svn repository and can be found here: http://batchfiles.googlecode.com/svn/trunk/Sweave.bat and http://batchfiles.googlecode.com/svn/trunk/Stangle.bat

Dec 20/10. Additional bug fixes were committed to the development repository today.

Dec 19/10. Version 0.6-1 for R 2.12.0 and later has uploaded to CRAN (and can also be accessed from the development repository). This is a bug fix release. The R_ARCH environmental variable, if set, can now be any of 32, i386, /i386, 64, x64, /x64. (Its available from the main CRAN site and the development repository and will be available shortly from the CRAN mirrors.)

The main changes is that they handle the new architecture-specific directory structure required in R 2.12.0 . Several lesser used commands were dropped.

Dec 12/10. Version 0.6-0 for R 2.12.0 has uploaded to CRAN (and can also be accessed from the development repository). The main changes is that they handle the new architecture-specific directory structure required in R 2.12.0 . Several lesser used commands were dropped.

May 31/09. clip2r.js added to development area. This utility is typically called from a vim macro which places the buffer into the clipboard and then launches clip2r.js. It then pastes the clipboard into R. See comments in file for using it from vim.

May 26/09. #Rscript.bat with bug fixes was uploaded to the development area. If test.bat is an R file with #Rscript.bat $0 $* as the first line it can be run from the Windows cmd console as test, as test.bat or can be double clicked from Windows Explorer whereas previously some but not all of these worked and which ones worked varied. Thanks to Nicholas Hirschey for pointing this out and testing.

May 25/09. batchfiles_0.5-0.zip is now on CRAN and should appear on the mirrors shortly. The new features are listed here, a list of included programs is shown here and further documentation can be found in the README here.

May 23/09. Batch files in devel version now work with Windows XP, Vista, Windows 7 and both 32 and 64 bit Windows. Thanks to Nicholas Hirschey for testing and contributions.

May 23/09. In the devel version jgr.bat automatically locates both R and that R library holding the JGR package and passes their paths to jgr.exe. Thus jgr installation only involves placing jgr.exe anywhere on the Windows PATH and installing the JGR R package (and optionally setting the version of java using jselect.exe). Note that jgr.bat is still in development and is not currently recommended for use.

May 7/09. Added Q8 to Troubleshooting FAQ below.

Jan 22/09. Rversions.hta now sets the .RData association as well. Also RExcelVersion.hta is like Rversions.hta but has some visual enhancements and testing so it works on XP as well (both thanks to Erich Neuwirth). RExcelVersion.hta is intended for use with the RExcel Excel addin but there is nothing specific to RExcel so it can be used apart from it as well. RExcelVersion.hta may eventually replace Rversions.hta; however, there may still be some development on it prior to that so for the moment its being kept separate.

Dec 12/08. New command find-miktex.hta to display path of the MiKTeX bin directory. Call from Windows console with no arguments or double click from Windows explorer and it will display the path to the MiKTeX executables in a browser-like window. (Internally this command uses the MiKTeX SDK to find MiKTeX. This is in contrast to the other utilities in this collection that use a heuristic.)

Dec 6/08. In the Modifying Path HOWTO we added information on setenv.exe, a free setx clone.

Nov 26/08. Added information on Windows 7 in the HOWTO section.

Oct 29/08. Added Q6 and Q7 to troubleshooting section.

Sep 27/08. Added information on Vista Run Commands (most work in XP too) in the HOWTO section.

August 2/08. Added information on Vista SP1 Performance Tuning in the HOWTO section below.

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 all 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 http://www.murdoch-sutherland.com/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.3-2 and prior were tested on XP only but later versions were tested on Vista and users report that they work on Windows 7 as well.

TROUBLESHOOTING FAQ

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 with MiKTeX for which a workaround will likely be forthcoming in version 2.8.0 of R. In the meantime here are three different solutions: (1) 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} (2) A more drastic solution, which is not recommended but has been reported to work, is to reinstall R into a directory whose pathname has no spaces in it. (3) Another solution (warning: I have not verified this one) is to set the SWEAVE_STYLEPATH_DEFAULT environment variable in Windows to FALSE. For more on SWEAVE_STYLEPATH_DEFAULT see the Sweave manual and this post. (There is information on setting environment variables in the HowTo section below.)

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, Path Manager or other 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.

Q5. Rcmd INSTALL ... does not work.

A5. This is a commonly caused by a problem in customizations you made to your Rprofile.site file. In R, this shows the path of that file:

file.path(R.home(), "etc", "Rprofile.site")

See this r-devel post for more info.

Q6. I created my own batch file which calls Rcmd.bat from the batchfiles distribution (or other bat file); however, after Rcmd runs it does not return to my batch file.

A6. In Windows, when one batch file invokes another by simply giving its name as in:

rem this is in a batch file
Rcmd.bat check %1

the called batch file does not return to the caller -- i.e. in this example Rcmd.bat would not return to the invoking batch file. In order to achieve automatic return the call batch command must be used:

:: if call were not used on 1st line processing would never reach: echo finished
call Rcmd.bat check %1
echo finished

This is a general aspect of Windows batch files and is not specific to Rcmd.bat .

Q7. As in R FAQ 2.8 I upgraded from one version of R to another, e.g. 2.7.2 to R 2.8.0, and then used

cd \Users\JoeDoe\Documents\R\win-library
movedir 2.7 2.8

(or used copydir) and then invoked the Packages | Update menu but now RGtk2 and packages depending on it do not work. (Although we know of no other packages to which this applies its possible that such exist. In that case use the analogous answer.)

A7. In 2.8.0 just reinstall RGtk2:

install.packages("RGtk2", dep = TRUE)

then exit and re-enter R.

R FAQ 2.8 actually recommends using update.packages(checkBuilt = TRUE, ask = FALSE) rather than the menu and its possible that that would have resolved the RGtk2 problem although it could also result in many packages being downloaded so it could add substantially to the time. [TODO: Resolve whether using checkBuilt makes a difference.]

Q8. I get an error message concerning a directory that seems unrelated to what I am doing.

A8. There is now defensive code included to automatically protect against bad paths but just in case it misses certain conditions check your PATH to see if it has a problem. For example, check if a directory is in your PATH but does not exist. The free Redmond Path utility or Path Manager can be used to easily remove the offending directory from your path. Also note that there are length limits to the path. See this link to Microsoft's knowledge base article.

Q9. Sweave.bat and Stangle.bat do not work.

A9. Make sure you are running such commands from a directory for which you have sufficient permissions. A good place to run them is in your home directory, i.e. the %userprofile% directory, or some subdirectory of that. Do not run it in the C:\Program Files tree. If the problem is that it does not work within TexMaker or TexMakerX then define R_HOME as described in Q4 above.

HOWTO

There are more HowTo's are in the Links box.

How to Find your PATH on Windows? From the Windows cmd line issue this command:

path

If you have a long path so that the output from the above is hard to read try this R command:

View(strsplit(Sys.getenv("PATH"), ";"))

Modifying PATH Users of the batchfiles presented here are largely freed from having to modify the path in the first place; however, if you do need to do it then this is how. The PATH command from the Windows console will change the PATH for that cmd session. See PATH /? for more info.

Here is an example of adding C:\ to the start of your path (for the remainder of the current cmd session only):

path C:\;%path%

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 available in Vista and Windows 7 (or at extra cost from the Windows resource kit for XP; however, there is a free clone called setenv.exe) or (3) the free Redmond Path utility or Path Manager which makes it particularly easy to set your path by providing a gui editor into which it dumps your path, one component per line, so you can visually edit it and save it back.

Set Environment Variables Permanently through batch SetEnv

Create Shortcut from cmd line See xxmklink.

Install package from CRAN Ordinarily you simply start R and choose the Packages | Install menu (or else use the R install.packages command):

install.packages("zoo")

If the package is one that comes with R itself, such as lattice, then you need to run R in elevated mode. (For ordinary packages this is not needed.) To run R in elevated mode, on your Windows 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 el.js and Rgui.bat batchfiles like this to start R as shown below and then proceed to Packages menu, as before:

el Rgui

Another way to run R elevated is to click the Windows Start button in the lower left of the screen and enter cmd.exe into the Search box terminating it not with Enter but with Shift-Ctrl-Enter. That will give a command line which is elevated. Then run R from the command line using the batchfiles' Rgui command.

(If despite doing the above that you get a message about packages.html not being writable then find the offending file in Windows Explorer and right-click that file's name choosing Properties > Security tab and reset the permissions appropriately. You may or may not also need to do the same thing on that file's folder.)

Run Commands A long list of commands that can be entered in a Windows console: Run Commands

Simple command line utilties for Windows Microsoft has a collection http://technet.microsoft.com/en-us/sysinternals and there is a collection of UNIX-like tools put together by Duncan Murdoch with a professional R-style installer http://www.murdoch-sutherland.com/Rtools . Several other collections are Bill Stewart's tools http://www.westmesatech.com/index.html and the Optimum X collection http://www.optimumx.com/downloads.html. Timo Salmi's cmd.exe script tricks http://www.netikka.net/tsneti/info/tscmd.php may let you write your own in certain cases.

File Associations File associations are performed from the command line using the assoc and ftype commands in Windows. From the Windows console try help assoc and help ftype and also try issuing the two commands without arguments to view the present associations.

AutoHotKey Scripts There are AutoHotKey scripts by Jose Quesada to send code from the vim editor to R, to start R and to autoclose parentheses.

Suspending a Task DTaskManager is a free 2000/XP/Vista Windows utility that can be used to suspend tasks.

Reg String to Start Rgui See https://stat.ethz.ch/pipermail/r-help/2010-January/224444.html. It does not start up a separate cmd window and works on Windows 7 too.

Ready Boost Windows Vista and higher allow one to use the storage on a USB key for extra cache space. This will improve performance, particularly if there was only a single hard drive and small main memory. Only USB keys with sufficiently fast storage will work. More information on this feature is available from:Tom Archer's MSDN blog and Tom Archer's FAQ.

User Account Control and Other Tweaks Windows 7 has improvements to make UAC less annoying; however, even if you do not have it certain Windows 7 features can be simulated in XP and Vista as discusssed Get Windows 7 Features Right Now.

Vista Performance Turning Microsoft has a free downloadable 14 page PDF document entitled Windows Vista Performance Tuning that discusses improving the performance of a Vista computer running the SP1 update. Also, ways to improve the performance of a Vista system (plus a link to an even longer list) was published in the NY Times Technology column October 9, 2008.

Am I Running Service Pack 1 (SP1) on Vista? 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.

Upgrade from XP to Windows 7 See PC World article

Powered by Google Project Hosting