Neal, R. M. (2003) ``Slice sampling'' (with discussion), Annals of Statistics, vol. 31, pp. 705-767: abstract, text from online journal site, associated references, associated software.The function here is designed for use as part of a larger MCMC program for some application.
Release of 17 March 2008: R file.
Note that an earlier release on 14 March 2008 had problems with the test function (but not with the actual slice sampling function).
You can obtain R from the R project web site.
Note that the full range of slice sampling procedures described in the above paper are implemented in my Software for Flexible Bayesian Modeling, but in a form that is not so easily adapted for use as part of another program.