# store the current directory
initial.dir<-getwd()
# change to the new directory
setwd("/home/jim/psych/risk/adol")
# load the necessary libraries
library(nlme)
# set the output file
sink("adolrisk03.out")
# load the dataset
...
# close the output file
sink()
# unload the libraries
detach("package:nlme")
# change back to the original directory
setwd(initial.dir)
参考:
ftp://cran.r-project.org/pub/R/doc/contrib/Lemon-kickstart/kr_scrpt.html