|
From: <gg...@us...> - 2008-09-16 09:04:04
|
Revision: 87
http://bugs-r.svn.sourceforge.net/bugs-r/?rev=87&view=rev
Author: ggorjan
Date: 2008-09-16 09:04:14 +0000 (Tue, 16 Sep 2008)
Log Message:
-----------
using temporary directory when working.directory=NULL
Modified Paths:
--------------
trunk/R2WinBUGS/R/bugs.R
trunk/R2WinBUGS/R/openbugs.R
trunk/R2WinBUGS/inst/NEWS
trunk/R2WinBUGS/man/bugs.Rd
Modified: trunk/R2WinBUGS/R/bugs.R
===================================================================
--- trunk/R2WinBUGS/R/bugs.R 2008-09-16 07:45:46 UTC (rev 86)
+++ trunk/R2WinBUGS/R/bugs.R 2008-09-16 09:04:14 UTC (rev 87)
@@ -11,6 +11,11 @@
newWINE=TRUE, WINEPATH=NULL, bugs.seed=NULL, summary.only=FALSE,
save.history=!summary.only)
{
+ if(!is.null(working.directory)) {
+ savedWD <- getwd()
+ setwd(working.directory)
+ on.exit(setwd(savedWD))
+ }
program <- match.arg(program)
if (missing(bugs.directory) &&
!is.null(bugs.dir <- getOption("R2WinBUGS.bugs.directory"))) { # requested by Jouni Kerman
@@ -23,7 +28,7 @@
n.chains, n.iter, n.burnin, n.thin, n.sims, DIC=DIC,
bugs.directory, working.directory, digits))
}
- ## Checking number of inits, which is NOT save here:
+ ## Checking number of inits, which is NOT saved here:
if(!missing(inits) && !is.function(inits) && !is.null(inits) && (length(inits) != n.chains))
stop("Number of initialized chains (length(inits)) != n.chains")
@@ -36,11 +41,15 @@
if(is.null(WINEPATH)) WINEPATH <- findUnixBinary(x="winepath")
}
- if(!is.null(working.directory)) {
- savedWD <- getwd()
- setwd(working.directory)
- on.exit(setwd(savedWD))
+ ## Move to working drirectory or temporary directory when NULL
+ if(is.null(working.directory)) {
+ working.directory <- tempdir()
}
+ savedWD <- getwd()
+ setwd(working.directory)
+ on.exit(setwd(savedWD))
+
+ ## model.file is not a file name but a model function
if(is.function(model.file)){
temp <- tempfile("model")
temp <-
Modified: trunk/R2WinBUGS/R/openbugs.R
===================================================================
--- trunk/R2WinBUGS/R/openbugs.R 2008-09-16 07:45:46 UTC (rev 86)
+++ trunk/R2WinBUGS/R/openbugs.R 2008-09-16 09:04:14 UTC (rev 87)
@@ -17,11 +17,15 @@
nThin <- n.thin
if(DIC) parameters.to.save <- c(parameters.to.save, "deviance")
parametersToSave <- parameters.to.save
- if(!is.null(working.directory)) {
- savedWD <- getwd()
- setwd(working.directory)
- on.exit(setwd(savedWD))
+
+ ## Move to working drirectory or temporary directory when NULL
+ if(is.null(working.directory)) {
+ working.directory <- tempdir()
}
+ savedWD <- getwd()
+ setwd(working.directory)
+ on.exit(setwd(savedWD))
+
if(!file.exists(modelFile)) {
stop(modelFile, " does not exist")
}
Modified: trunk/R2WinBUGS/inst/NEWS
===================================================================
--- trunk/R2WinBUGS/inst/NEWS 2008-09-16 07:45:46 UTC (rev 86)
+++ trunk/R2WinBUGS/inst/NEWS 2008-09-16 09:04:14 UTC (rev 87)
@@ -2,13 +2,15 @@
=====================
Update 2.1-8?
+- If working.directory=NULL (the default setting), then a temporary
+ directory is used as a working directory to prevent overwriting/removing
+ the existing files.
- File script.txt is also removed when clearWD=TRUE.
-
- If model.file does not have a "txt" extension, then it is temporarily
- copied to a file with "txt" extension in the working directory and
- removed at the end of WinBUGS run.
+ copied to a file with "txt" extension in the working directory and
+ removed at the end of WinBUGS run.
-Update 2.1-7
+Update 2.1-7
- this file is now available as NEWS file in top folder of installed package
Update 2.1-6 (23 August 2007):
Modified: trunk/R2WinBUGS/man/bugs.Rd
===================================================================
--- trunk/R2WinBUGS/man/bugs.Rd 2008-09-16 07:45:46 UTC (rev 86)
+++ trunk/R2WinBUGS/man/bugs.Rd 2008-09-16 09:04:14 UTC (rev 87)
@@ -82,7 +82,8 @@
choice is not available in S-PLUS.}
\item{working.directory}{sets working directory during execution of
this function; \pkg{WinBUGS}' in- and output will be stored in this
- directory; if \code{NULL}, the current working directory is chosen.}
+ directory; if \code{NULL}, a temporary working directory via
+ \code{\link{tempdir}} is used.}
\item{clearWD}{logical; indicating whether the files \file{data.txt},
\file{inits[1:n.chains].txt}, \file{log.odc}, \file{codaIndex.txt},
and \file{coda[1:nchains].txt} should be removed after \pkg{WinBUGS} has
@@ -243,8 +244,7 @@
## also you need write access in the working directory:
schools.sim <- bugs(data, inits, parameters, model.file,
n.chains=3, n.iter=5000,
- bugs.directory="c:/Program Files/WinBUGS14/",
- working.directory=NULL, clearWD=TRUE)
+ bugs.directory="c:/Program Files/WinBUGS14/")
print(schools.sim)
plot(schools.sim)
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|