From: <gg...@us...> - 2007-08-23 07:44:09
|
Revision: 37 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=37&view=rev Author: ggorjan Date: 2007-08-23 00:44:10 -0700 (Thu, 23 Aug 2007) Log Message: ----------- now default argument values should also work for Linux side using WINE + some code cleanup; hold your breath plase until I test this on Windows machine Modified Paths: -------------- trunk/R2WinBUGS/Changes trunk/R2WinBUGS/DESCRIPTION trunk/R2WinBUGS/R/bugs.R trunk/R2WinBUGS/R/bugs.run.R trunk/R2WinBUGS/R/bugs.script.R trunk/R2WinBUGS/R/wineutils.R trunk/R2WinBUGS/man/bugs.Rd trunk/R2WinBUGS/man/bugs.run.Rd trunk/R2WinBUGS/man/bugs.script.Rd Modified: trunk/R2WinBUGS/Changes =================================================================== --- trunk/R2WinBUGS/Changes 2007-08-08 11:31:43 UTC (rev 36) +++ trunk/R2WinBUGS/Changes 2007-08-23 07:44:10 UTC (rev 37) @@ -1,6 +1,13 @@ Changes to R2WinBUGS: ===================== +Update 2.1-6 (23 August 2007): +- reverting back to use thin.updater since it is faster, however CODA files + have "wrong" indexes +- WINE arguments are now set in such a way that defaults work on Windows + and Linux +- minor formatting in the code and help files + Update 2.1-5 (12 June 2007): - proper indexing of CODA files also in R version - fixed useWINE documentation in bugs help page Modified: trunk/R2WinBUGS/DESCRIPTION =================================================================== --- trunk/R2WinBUGS/DESCRIPTION 2007-08-08 11:31:43 UTC (rev 36) +++ trunk/R2WinBUGS/DESCRIPTION 2007-08-23 07:44:10 UTC (rev 37) @@ -1,7 +1,7 @@ Package: R2WinBUGS Title: Running WinBUGS and OpenBUGS from R / S-PLUS Date: 2007-05-20 -Version: 2.1-5 +Version: 2.1-6 Author: originally written by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. Modified: trunk/R2WinBUGS/R/bugs.R =================================================================== --- trunk/R2WinBUGS/R/bugs.R 2007-08-08 11:31:43 UTC (rev 36) +++ trunk/R2WinBUGS/R/bugs.R 2007-08-23 07:44:10 UTC (rev 37) @@ -7,38 +7,30 @@ bugs.directory="c:/Program Files/WinBUGS14/", program=c("WinBUGS", "OpenBUGS", "winbugs", "openbugs"), working.directory=NULL, - clearWD=FALSE, useWINE=.Platform$OS.type != "windows", WINE=Sys.getenv("WINE"), - newWINE=FALSE, WINEPATH=NULL) + clearWD=FALSE, useWINE=.Platform$OS.type != "windows", WINE=NULL, + newWINE=TRUE, WINEPATH=NULL) { program <- match.arg(program) if(program %in% c("openbugs", "OpenBUGS", "OpenBugs")) { - if(is.R()) { - ## If OpenBUGS, we only call openbugs() and exit... - return(openbugs(data, inits, parameters.to.save, model.file, - n.chains, n.iter, n.burnin, n.thin, DIC=DIC, - bugs.directory, working.directory, digits)) - } else { - stop ("OpenBUGS is not yet available in S-PLUS") - } + if(!is.R()) stop("OpenBUGS is not yet available in S-PLUS") + ## If OpenBUGS, we only call openbugs() and exit... + return(openbugs(data, inits, parameters.to.save, model.file, + n.chains, n.iter, n.burnin, n.thin, DIC=DIC, + bugs.directory, working.directory, digits)) } ## Checking number of inits, which is NOT save here: if(!missing(inits) && !is.function(inits) && !is.null(inits) && (length(inits) != n.chains)) stop("Number of initialized chains (length(inits)) != n.chains") + + ## Wine if(useWINE) { if(!is.R()) - stop ("Non-Windows platforms not yet supported in R2WinBUGS for S-PLUS") - ## attempt to find wine and winepath - if(!nchar(WINE)) { - WINE <- system("locate wine | grep bin/wine$", intern=TRUE) - WINE <- WINE[length(WINE)] - } - if(!length(WINE)) stop("couldn't locate WINE binary") - if(!nchar(WINEPATH)) { - WINEPATH <- system("locate winepath | grep bin/winepath$", intern=TRUE) - WINEPATH <- WINEPATH[length(WINEPATH)] - } - if(!length(WINEPATH)) stop("couldn't locate WINEPATH binary") + stop("Non-Windows platforms not yet supported in R2WinBUGS for S-PLUS") + ## Attempt to find wine and winepath + if(is.null(WINE)) WINE <- findUnixBinary(x="wine") + if(is.null(WINEPATH)) WINEPATH <- findUnixBinary(x="winepath") } + if(!is.null(working.directory)) { savedWD <- getwd() setwd(working.directory) @@ -50,8 +42,9 @@ stop(paste(model.file, "is a directory, but a file is required.")) if(!(length(data) == 1 && is.vector(data) && is.character(data) && data == "data.txt")) { bugs.data(data, dir=getwd(), digits) - } else if(!file.exists(data)) - stop("File data.txt does not exist.") + } else { + if(!file.exists(data)) stop("File data.txt does not exist.") + } bugs.inits(inits, n.chains, digits) if(DIC) parameters.to.save <- c(parameters.to.save, "deviance") ## Model files with extension ".bug" need to be renamed to ".txt" @@ -67,7 +60,7 @@ bin=bin, DIC=DIC, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) bugs.run(n.burnin, bugs.directory, WINE=WINE, useWINE=useWINE, - WINEPATH=WINEPATH) + newWINE=newWINE, WINEPATH=WINEPATH) if(codaPkg) return(file.path(getwd(), paste("coda", 1:n.chains, ".txt", sep=""))) sims <- c(bugs.sims(parameters.to.save, n.chains, n.iter, n.burnin, Modified: trunk/R2WinBUGS/R/bugs.run.R =================================================================== --- trunk/R2WinBUGS/R/bugs.run.R 2007-08-08 11:31:43 UTC (rev 36) +++ trunk/R2WinBUGS/R/bugs.run.R 2007-08-23 07:44:10 UTC (rev 37) @@ -1,51 +1,55 @@ "bugs.run" <- - function(n.burnin, bugs.directory, WINE = "", - useWINE = .Platform$OS.type != "windows", - newWINE = TRUE, WINEPATH = NULL){ - -if(useWINE && !is.R()) - stop ("Non-Windows platforms not yet supported in R2WinBUGS for S-PLUS") -if(useWINE && !newWINE) bugs.directory <- win2native(bugs.directory) + function(n.burnin, bugs.directory, + useWINE=.Platform$OS.type != "windows", WINE=NULL, + newWINE=TRUE, WINEPATH=NULL) +{ -## Update the lengths of the adaptive phases in the Bugs updaters + if(useWINE && !is.R()) + stop("Non-Windows platforms not yet supported in R2WinBUGS for S-PLUS") + + ## Is bugs.directory defined in Windows (where second character is : + ## i.e. C:\Program...) or Unix style path? + test <- substr(bugs.directory, start=2, stop=2) == ":" + if(useWINE && test) { + bugs.directory <- win2native(bugs.directory, newWINE=newWINE, WINEPATH=WINEPATH) + } + + ## Update the lengths of the adaptive phases in the Bugs updaters try(bugs.update.settings(n.burnin, bugs.directory)) -## Return the lengths of the adaptive phases to their original settings - if (is.R()){ - on.exit(try(file.copy(file.path(bugs.directory, "System/Rsrc/Registry_Rsave.odc"), - file.path(bugs.directory, "System/Rsrc/Registry.odc"), - overwrite = TRUE))) - } else { - on.exit(try(splus.file.copy(file.path(bugs.directory, "System/Rsrc/Registry_Rsave.odc"), - file.path(bugs.directory, "System/Rsrc/Registry.odc"), - overwrite = TRUE))) - } - -## Search Win*.exe (WinBUGS executable) within bugs.directory - dos.location <- file.path(bugs.directory, - grep("^Win[[:alnum:]]*[.]exe$", list.files(bugs.directory), value = TRUE)[1]) - if(!file.exists(dos.location)) + + ## Return the lengths of the adaptive phases to their original settings + if(is.R()) { + .fileCopy <- file.copy + } else { + .fileCopy <- splus.file.copy + } + on.exit(try(.fileCopy(file.path(bugs.directory, "System/Rsrc/Registry_Rsave.odc"), + file.path(bugs.directory, "System/Rsrc/Registry.odc"), + overwrite=TRUE))) + + ## Search Win*.exe (WinBUGS executable) within bugs.directory + dos.location <- file.path(bugs.directory, + grep("^Win[[:alnum:]]*[.]exe$", + list.files(bugs.directory), value=TRUE)[1]) + if(!file.exists(dos.location)) stop(paste("WinBUGS executable does not exist in", bugs.directory)) -## Call Bugs and have it run with script.txt + + ## Call Bugs and have it run with script.txt bugsCall <- paste("\"", dos.location, "\" /par \"", - native2win(file.path(getwd(), "script.txt"), newWINE = newWINE, WINEPATH = WINEPATH), - "\"", sep = "") - if (useWINE) - bugsCall <- paste(WINE, bugsCall) + native2win(file.path(getwd(), "script.txt"), + useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH), + "\"", sep="") + if(useWINE) bugsCall <- paste(WINE, bugsCall) temp <- system(bugsCall) + if(temp == -1) + stop("Error in bugs.run().\nCheck that WinBUGS is in the specified directory.") - if(temp == -1) - stop("Error in bugs.run().\nCheck that WinBUGS is in the specified directory.") -## Stop and print an error message if Bugs did not run correctly + ## Stop and print an error message if Bugs did not run correctly if(is.R()) { - if(length(grep("Bugs did not run correctly", - scan("coda1.txt", character(), quiet=TRUE, sep="\n"))) > 0) - stop("Look at the log file and\ntry again with debug=TRUE and figure out what went wrong within Bugs.") + tmp <- scan("coda1.txt", character(), quiet=TRUE, sep="\n") } else { - if (length(grep("Bugs did not run correctly", - scan("coda1.txt", character(), sep="\n"))) > 0) - stop("Look at the log file and\ntry again with debug=TRUE and figure out what went wrong within Bugs.") + tmp <- scan("coda1.txt", character(), sep="\n") } + if(length(grep("Bugs did not run correctly", tmp)) > 0) + stop("Look at the log file and\ntry again with 'debug=TRUE' to figure out what went wrong within Bugs.") } - - - Modified: trunk/R2WinBUGS/R/bugs.script.R =================================================================== --- trunk/R2WinBUGS/R/bugs.script.R 2007-08-08 11:31:43 UTC (rev 36) +++ trunk/R2WinBUGS/R/bugs.script.R 2007-08-23 07:44:10 UTC (rev 37) @@ -1,50 +1,65 @@ "bugs.script" <- -function (parameters.to.save, n.chains, n.iter, n.burnin, - n.thin, model.file, debug=FALSE, is.inits, bin, - DIC = FALSE, useWINE = FALSE, newWINE = FALSE, WINEPATH = NULL){ -### Write file script.txt for Bugs to read + function(parameters.to.save, n.chains, n.iter, n.burnin, + n.thin, model.file, debug=FALSE, is.inits, bin, + DIC=FALSE, useWINE=.Platform$OS.type != "windows", + newWINE=TRUE, WINEPATH=NULL) +{ + ## Write file script.txt for Bugs if((ceiling(n.iter/n.thin) - ceiling(n.burnin/n.thin)) < 2) stop ("(n.iter-n.burnin)/n.thin must be at least 2") working.directory <- getwd() script <- "script.txt" - model <- if(length(grep("\\\\", model.file)) || length(grep("/", model.file))){ - model.file - } else file.path(working.directory, model.file) + + test <- length(grep("\\\\", model.file)) || length(grep("/", model.file)) + model <- ifelse(test, model.file, file.path(working.directory, model.file)) + model <- native2win(model, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) + data <- file.path(working.directory, "data.txt") + data <- native2win(data, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) + coda <- file.path(working.directory, "coda") - logfile <- file.path(working.directory, "log.odc") - logfileTxt <- file.path(working.directory, "log.txt") - inits <- sapply(paste(working.directory, "/inits", 1:n.chains, ".txt", sep=""), - function(x) native2win(x, , WINEPATH = WINEPATH)) + coda <- native2win(coda, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) + + logFile <- file.path(working.directory, "log.odc") + logFile <- native2win(logFile, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) + logFileTxt <- file.path(working.directory, "log.txt") + logFileTxt <- native2win(logFileTxt, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) + + inits <- paste(working.directory, "/inits", 1:n.chains, ".txt", sep="") + inits <- sapply(inits, function(x) native2win(x, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH)) + initlist <- paste("inits (", 1:n.chains, ", '", inits, "')\n", sep="") + savelist <- paste("set (", parameters.to.save, ")\n", sep="") redo <- ceiling((n.iter-n.burnin)/(n.thin*bin)) - thinUpdateCommand <- paste("thin.updater (", n.thin, ")\n", - "update (", ceiling(n.burnin/n.thin), ")\n", sep = "") + thinUpdate <- paste("thin.updater (", n.thin, ")\n", + "update (", ceiling(n.burnin/n.thin), ")\n", sep="") cat( "display ('log')\n", - "check ('", native2win(model, WINEPATH=WINEPATH), "')\n", - "data ('", native2win(data, WINEPATH=WINEPATH), "')\n", + "check ('", model, "')\n", + "data ('", data, "')\n", "compile (", n.chains, ")\n", if(is.inits) initlist, "gen.inits()\n", - thinUpdateCommand, + thinUpdate, savelist, if(DIC) "dic.set()\n", rep( - c("update (", formatC(ceiling(bin), format = "d"), ")\n", - "coda (*, '", native2win(coda, WINEPATH=WINEPATH), "')\n"),redo), + c("update (", formatC(ceiling(bin), format="d"), ")\n", + "coda (*, '", coda, "')\n"),redo), "stats (*)\n", if(DIC) "dic.stats()\n", "history (*)\n", - "save ('", native2win(logfile, WINEPATH=WINEPATH), "')\n", - "save ('", native2win(logfileTxt, WINEPATH=WINEPATH), "')\n", + "save ('", logFile, "')\n", + "save ('", logFileTxt, "')\n", file=script, sep="", append=FALSE) - if (!debug) cat ("quit ()\n", file=script, append=TRUE) - sims.files <- paste ("coda", 1:n.chains, ".txt", sep="") - for (i in 1:n.chains) cat ("WinBUGS did not run correctly.\n", - file=sims.files[i], append=FALSE) + + if(!debug) cat("quit ()\n", file=script, append=TRUE) + + sims.files <- paste("coda", 1:n.chains, ".txt", sep="") + for(i in 1:n.chains) + cat("WinBUGS did not run correctly.\n", file=sims.files[i], append=FALSE) } Modified: trunk/R2WinBUGS/R/wineutils.R =================================================================== --- trunk/R2WinBUGS/R/wineutils.R 2007-08-08 11:31:43 UTC (rev 36) +++ trunk/R2WinBUGS/R/wineutils.R 2007-08-23 07:44:10 UTC (rev 37) @@ -1,65 +1,110 @@ -## from Jun Yan's rbugs package, extended +findUnixBinary <- function(x) +{ + ## --- Environmental variable --- + tmp <- Sys.getenv(toupper(x)) + if(nchar(tmp) != 0) return(tmp) + ## else -if (is.R()){ + ## --- Standard place --- + tmp <- paste("/usr/bin", x, sep="") + if(file.exists(tmp)) return(tmp) + ## else ... -## get drive mapping table from ~/.wine/config -winedriveMap <- function(config="~/.wine/config") { - if (!file.exists(config)) return (NULL); - con <- readLines(config) - con <- con[- grep("^;", con)] - drive <- con[grep("^\\[Drive ", con)] - drive <- substr(drive, 8, 8) - drive <- paste(drive, ":", sep="") - path <- con[grep("Path", con)] - len <- length(drive) - path <- path[1:len] - dir <- sapply(path, - function(x) { - foo <- unlist(strsplit(x, "\"")) - foo[length(foo)] - }) - dir <- sub("%HOME%",tools::file_path_as_absolute("~"),dir) - data.frame(drive = I(drive), path = I(dir), row.names=NULL) -} + ## --- Which --- + tmp <- system(paste("which ", x, sep=""), intern=TRUE) + if(length(tmp) != 0) return(tmp) + ## else .. -## translate windows dir to native dir -winedriveTr <- function(windir, DriveTable=winedriveMap()) { - win.dr <- substr(windir, 1, 2) - ind <- pmatch(toupper(win.dr), DriveTable$drive) - native.dr <- DriveTable$path[ind] - sub(win.dr, native.dr, windir) + ## --- Locate --- + tmp <- system(paste("locate ", x, " | grep bin/", x, "$", sep=""), intern=TRUE) + tmp <- tmp[length(tmp)] ## keep only last hit + if(length(tmp) > 0) return(tmp) + + stop(paste("couldn't find", x, "binary file")) } -## translate full Unix path to Wine path -winedriveRTr <- function(unixpath, DriveTable=winedriveMap()) { - blocks <- strsplit(unixpath,"/")[[1]] - cblocks <- c("/",sapply(1+seq(along=blocks[-1]), - function(n) paste(blocks[1:n],collapse="/"))) - path <- match(cblocks,DriveTable$path) - if (any(!is.na(path))) { - unixdir <- cblocks[which.min(path)] - windrive <- paste(DriveTable$drive[min(path,na.rm=TRUE)],"/",sep="") - winpath <- sub("//","/",sub(unixdir,windrive,unixpath)) ## kluge - } else stop("can't find equivalent Windows path: file may be inaccessible") - winpath +native2win <- function(x, useWINE=.Platform$OS.type != "windows", + newWINE=TRUE, WINEPATH=NULL) +{ + ## Translate Unix path to Windows (wine) path + if(useWINE) { + if(newWINE) { + if(is.null(WINEPATH)) WINEPATH <- findUnixBinary(x="winepath") + x <- system(paste(WINEPATH, "-w", x), intern=TRUE) + gsub("\\\\", "/", x) ## under wine BUGS cannot use \ or \\ + } else { + winedriveRTr(x) + } + } else { + x + } } +## TODO: why are we masking these functions in S-PLUS -win2native <- function(x, useWINE=.Platform$OS.type != "windows") { # win -> native - if (useWINE) winedriveTr(x) - else x -} +if(is.R()) { -} # end if (is.R()) + win2native <- function(x, useWINE=.Platform$OS.type != "windows", + newWINE=TRUE, WINEPATH=NULL) + { + ## Translate Windows path to native (unix) path + if(useWINE) { + if(newWINE) { + if(is.null(WINEPATH)) WINEPATH <- findUnixBinary(x="winepath") + system(paste(WINEPATH, " \"", x, "\"", sep=""), intern=TRUE) + } else { + winedriveTr(x) + } + } else { + x + } + } -native2win <- function(x, useWINE=.Platform$OS.type != "windows", newWINE=TRUE, WINEPATH=NULL) { # native -> win - if(is.R()){ - if (useWINE && !newWINE) return(winedriveRTr(x)) - if (useWINE && newWINE) { - x <- system(paste(WINEPATH, "-w", x), intern = TRUE) - return(gsub("\\\\", "/", x)) ## under wine BUGS cannot use \ or \\ - } else x - } else { #S-PLUS - gsub("\\\\", "/", x) + winedriveMap <- function(config="~/.wine/config") + { + ## Get drive mapping table from ~/.wine/config + if(!file.exists(config)) return(NULL); + con <- readLines(config) + con <- con[- grep("^;", con)] + drive <- con[grep("^\\[Drive ", con)] + drive <- substr(drive, 8, 8) + drive <- paste(drive, ":", sep="") + path <- con[grep("Path", con)] + len <- length(drive) + path <- path[1:len] + dir <- sapply(path, + function(x) { + foo <- unlist(strsplit(x, "\"")) + foo[length(foo)] + }) + dir <- sub("%HOME%",tools::file_path_as_absolute("~"),dir) + data.frame(drive=I(drive), path=I(dir), row.names=NULL) } -} + + winedriveTr <- function(windir, DriveTable=winedriveMap()) + { + ## Translate Windows path to native (Unix) path + win.dr <- substr(windir, 1, 2) + ind <- pmatch(toupper(win.dr), DriveTable$drive) + native.dr <- DriveTable$path[ind] + sub(win.dr, native.dr, windir) + } + + winedriveRTr <- function(unixpath, DriveTable=winedriveMap()) + { + ## Translate Unix path to Windows (wine) path + blocks <- strsplit(unixpath,"/")[[1]] + cblocks <- c("/",sapply(1+seq(along=blocks[-1]), + function(n) paste(blocks[1:n],collapse="/"))) + path <- match(cblocks,DriveTable$path) + if(any(!is.na(path))) { + unixdir <- cblocks[which.min(path)] + windrive <- paste(DriveTable$drive[min(path,na.rm=TRUE)],"/",sep="") + winpath <- sub("//","/",sub(unixdir,windrive,unixpath)) ## kludge + } else { + stop("can't find equivalent Windows path: file may be inaccessible") + } + winpath + } + +} # end of if(is.R()) Modified: trunk/R2WinBUGS/man/bugs.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.Rd 2007-08-08 11:31:43 UTC (rev 36) +++ trunk/R2WinBUGS/man/bugs.Rd 2007-08-23 07:44:10 UTC (rev 37) @@ -3,8 +3,8 @@ \title{Run WinBUGS and OpenBUGS from R or S-PLUS} \description{The \code{bugs} function takes data and starting values as - input. It automatically writes a WinBUGS script, calls the model, and - saves the simulations for easy access in R or S-PLUS.} + input. It automatically writes a \pkg{WinBUGS} script, calls the model, and + saves the simulations for easy access in \R or S-PLUS.} \usage{ bugs(data, inits, parameters.to.save, model.file="model.bug", @@ -15,25 +15,25 @@ bugs.directory="c:/Program Files/WinBUGS14/", program=c("WinBUGS", "OpenBUGS", "winbugs", "openbugs"), working.directory=NULL, clearWD=FALSE, - useWINE=.Platform$OS.type != "windows", WINE=Sys.getenv("WINE"), - newWINE=FALSE, WINEPATH=NULL) + useWINE=.Platform$OS.type != "windows", WINE=NULL, + newWINE=TRUE, WINEPATH=NULL) } \arguments{ \item{data}{either a named list (names corresponding to variable names - in the \code{model.file}) of the data for the WinBUGS model, + in the \code{model.file}) of the data for the \pkg{WinBUGS} model, \emph{or} a vector or list of the names of the data objects used by the model. If \code{data="data.txt"}, it is assumed that data have already been written to the working directory in a file called \file{data.txt}, e.g. by the function \code{\link{bugs.data}}.} \item{inits}{a list with \code{n.chains} elements; each element of the - list is itself a list of starting values for the WinBUGS model, + list is itself a list of starting values for the \pkg{WinBUGS} model, \emph{or} a function creating (possibly random) initial values. Alternatively, if \code{inits=NULL}, initial values are generated - by WinBUGS.} + by \pkg{WinBUGS}.} \item{parameters.to.save}{character vector of the names of the parameters to save which should be monitored} - \item{model.file}{file containing the model written in WinBUGS code. + \item{model.file}{file containing the model written in \pkg{WinBUGS} code. The extension can be either \file{.bug} or \file{.txt}. If the extension is \file{.bug} and \code{program=="WinBUGS"}, a copy of the file with extension \file{.txt} will be created @@ -53,69 +53,76 @@ \item{bin}{number of iterations between saving of results (i.e. the coda files are saved after each \code{bin} iterations); default is to save only at the end.} - \item{debug}{if \code{FALSE} (default), WinBUGS is closed automatically - when the script has finished running, otherwise WinBUGS remains open + \item{debug}{if \code{FALSE} (default), \pkg{WinBUGS} is closed automatically + when the script has finished running, otherwise \pkg{WinBUGS} remains open for further investigation} \item{DIC}{logical; if \code{TRUE} (default), compute deviance, pD, - and DIC. This is done in WinBUGS directly using the rule \code{pD = + and DIC. This is done in \pkg{WinBUGS} directly using the rule \code{pD = Dbar - Dhat}. If there are less iterations than required for the adaptive phase, the rule \code{pD=var(deviance) / 2} is used.} - \item{digits}{number of significant digits used for WinBUGS input, see + \item{digits}{number of significant digits used for \pkg{WinBUGS} input, see \code{\link{formatC}}} \item{codaPkg}{logical; if \code{FALSE} (default) a \code{bugs} object - is returned, if \code{TRUE} file names of WinBUGS output are + is returned, if \code{TRUE} file names of \pkg{WinBUGS} output are returned for easy access by the \pkg{coda} package through function \code{\link{read.bugs}} (not used if \code{program="OpenBUGS"}).} - \item{bugs.directory}{directory that contains the WinBUGS executable} + \item{bugs.directory}{directory that contains the \pkg{WinBUGS} executable} \item{program}{the program to use, either \code{winbugs}/\code{WinBUGS} or \code{openbugs}/\code{OpenBUGS}, the latter makes use of function \code{\link{openbugs}} and requires the CRAN package \pkg{BRugs}. The \code{openbugs}/\code{OpenBUGS} choice is not available in S-PLUS.} \item{working.directory}{sets working directory during execution of - this function; WinBUGS' in- and output will be stored in this + this function; \pkg{WinBUGS}' in- and output will be stored in this directory; if \code{NULL}, the current working directory is chosen.} \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 WinBUGS has + and \file{coda[1:nchains].txt} should be removed after \pkg{WinBUGS} has finished. If set to \code{TRUE}, this argument is only respected if \code{codaPkg=FALSE}.} + \item{useWINE}{logical; attempt to use the WINE emulator to run - WinBUGS, defaults to \code{FALSE} on Windows, and \code{TRUE} - otherwise. If WINE is used, the arguments \code{bugs.directory} and - \code{working.directory} must be given in form of Linux paths rather - than Windows paths (if not \code{NULL}). The \code{useWINE=TRUE} - option is not available in S-PLUS.} - \item{WINE}{character; name of WINE binary file} - \item{newWINE}{Set this one to \code{TRUE} for new versions of WINE.} - \item{WINEPATH}{Path to WINE binary file, it is tried hard to get the - information automatically if not given.} + \pkg{WinBUGS}, defaults to \code{FALSE} on Windows, and \code{TRUE} + otherwise. Not available in S-PLUS.} + \item{WINE}{character, path to \file{wine} binary file, it is + tried hard to get the information automatically if not given.} + \item{newWINE}{Use new versions of WINE that have \file{winepath} + utility} + \item{WINEPATH}{character, path to \file{winepath} binary file, it is + tried hard to get the information automatically if not given.} } \details{ To run: \enumerate{ - \item Write a WinBUGS model in a ASCII file. - \item Go into R / S-PLUS. - \item Prepare the inputs to the \code{bugs} function and run it (see - Example). - \item A WinBUGS window will pop up and R / S-PLUS will freeze - up. The model will now run in WinBUGS. It might take awhile. You - will see things happening in the Log window within WinBUGS. When - WinBUGS is done, its window will close and R / S-PLUS will work + \item Write a \pkg{WinBUGS} model in an ASCII file (hint: use + \code{\link{write.model}}). + \item Go into \R / S-PLUS. + \item Prepare the inputs for the \code{bugs} function and run it (see + Example section). + \item A \pkg{WinBUGS} window will pop up and \R / S-PLUS will freeze + up. The model will now run in \pkg{WinBUGS}. It might take awhile. You + will see things happening in the Log window within \pkg{WinBUGS}. When + \pkg{WinBUGS} is done, its window will close and \R / S-PLUS will work again. \item If an error message appears, re-run with \code{debug=TRUE}. } BUGS version support: \itemize{ - \item WinBUGS 1.4* (this is the only version that works under Linux) - \item OpenBUGS 2.* (via argument \code{program="OpenBUGS"}) + \item \pkg{WinBUGS} 1.4* (this is the only version that works under Linux) + \item \pkg{OpenBUGS} 2.* (via argument \code{program="OpenBUGS"}) } + + If \code{useWINE=TRUE} is used, all paths (such as + \code{working.directory} and \code{model.file}, must be given in + native (Unix) style, but \code{working.directory} can be given as + native(Unix) or Windows path style. This is done to achieve greatest + portability with default argument value for \code{working.directory}. } \value{ If \code{codaPkg=TRUE} the returned values are the names - of coda output files written by WinBUGS containing + of coda output files written by \pkg{WinBUGS} containing the Markov Chain Monte Carlo output in the CODA format. This is useful for direct access with \code{\link{read.bugs}}. @@ -154,7 +161,7 @@ \item{indexes.short}{indexes of \code{root.short}} \item{last.values}{list of simulations from the most recent iteration; they can be used as starting points if you wish to run - WinBUGS for further iterations} + \pkg{WinBUGS} for further iterations} \item{pD}{an estimate of the effective number of parameters, for calculations see the section \dQuote{Arguments}.} \item{DIC}{\code{mean(deviance) + pD}} Modified: trunk/R2WinBUGS/man/bugs.run.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.run.Rd 2007-08-08 11:31:43 UTC (rev 36) +++ trunk/R2WinBUGS/man/bugs.run.Rd 2007-08-23 07:44:10 UTC (rev 37) @@ -2,30 +2,27 @@ \alias{bugs.run} \title{Calling WinBUGS} -\description{Updates the lengths of the adaptive phases in the WinBUGS - registry (using \code{\link{bugs.update.settings}}), calls WinBUGS and - runs it with \file{script.txt} - intended for internal use} +\description{Updates the lengths of the adaptive phases in the + \pkg{WinBUGS} registry (using \code{\link{bugs.update.settings}}), + calls \pkg{WinBUGS} and runs it with \file{script.txt} - intended for + internal use} \usage{ -bugs.run(n.burnin, bugs.directory, WINE = "", - useWINE = .Platform$OS.type != "windows", - newWINE = TRUE, WINEPATH = NULL) +bugs.run(n.burnin, bugs.directory, + useWINE=.Platform$OS.type != "windows", WINE=NULL, + newWINE=TRUE, WINEPATH=NULL) } \arguments{ \item{n.burnin}{length of burn in} - \item{bugs.directory}{directory that contains the WinBUGS executable} - \item{WINE}{name of WINE binary, for Windows emulation} - \item{useWINE}{logical; attempt to use the WINE emulator to run WinBUGS, - defaults to \code{TRUE} on Windows, and \code{FALSE} otherwise. - The \code{useWINE = TRUE} option is not available in S-PLUS.} - \item{newWINE}{set this one to \code{TRUE} for new versions of WINE.} - \item{WINEPATH}{Path the WINE, \code{bugs} tries hard to get the - information automatically and pass it to this function, if not - given.} + \item{bugs.directory}{directory that contains the \pkg{WinBUGS} executable} + \item{useWINE}{as in \code{\link{bugs}} meta function} + \item{WINE}{as in \code{\link{bugs}} meta function} + \item{newWINE}{as in \code{\link{bugs}} meta function} + \item{WINEPATH}{as in \code{\link{bugs}} meta function} } \value{Nothing, but has side effects as documented in - \code{\link{bugs.update.settings}} and calls WinBUGS.} + \code{\link{bugs.update.settings}} and calls \pkg{WinBUGS}.} \seealso{The main function to be called by the user is \code{\link{bugs}}.} \keyword{internal} Modified: trunk/R2WinBUGS/man/bugs.script.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.script.Rd 2007-08-08 11:31:43 UTC (rev 36) +++ trunk/R2WinBUGS/man/bugs.script.Rd 2007-08-23 07:44:10 UTC (rev 37) @@ -3,13 +3,13 @@ \title{Writes script for running WinBUGS} -\description{Write file \file{script.txt} for WinBUGS to read - intended - for internal use} +\description{Write file \file{script.txt} for \pkg{WinBUGS} to read - + intended for internal use} \usage{ bugs.script(parameters.to.save, n.chains, n.iter, n.burnin, n.thin, - model.file, debug = FALSE, is.inits, bin, DIC = FALSE, - useWINE = FALSE, newWINE = FALSE, WINEPATH = NULL) + model.file, debug=FALSE, is.inits, bin, DIC=FALSE, + useWINE=.Platform$OS.type != "windows", newWINE=TRUE, WINEPATH=NULL) } \arguments{ \item{parameters.to.save}{parameters that should be monitored} @@ -17,20 +17,17 @@ \item{n.iter}{number of total iterations (including burn in)} \item{n.burnin}{length of burn in} \item{n.thin}{size of thinning parameter} - \item{model.file}{file containing the model written in WinBUGS code} - \item{debug}{if \code{FALSE}, WinBUGS is closed automatically, - otherwise WinBUGS remains open for further investigation} + \item{model.file}{file containing the model written in \pkg{WinBUGS} code} + \item{debug}{if \code{FALSE}, \pkg{WinBUGS} is closed automatically, + otherwise \pkg{WinBUGS} remains open for further investigation} \item{is.inits}{logical; whether initial values are given by the user - (\code{TRUE}) or have to be generated by WinBUGS} + (\code{TRUE}) or have to be generated by \pkg{WinBUGS}} \item{bin}{number of iterations between saving of results} \item{DIC}{logical; if \code{TRUE}, compute deviance, pD, and DIC - automatically in WinBUGS} - \item{useWINE}{logical; use WINE to run WinBUGS under Linux. - The \code{useWINE = TRUE} option is not available in S-PLUS.} - \item{newWINE}{set this one to \code{TRUE} for new versions of WINE.} - \item{WINEPATH}{Path the WINE, \code{bugs} tries hard to get the - information automatically and pass it to this function, if not - given.} + automatically in \pkg{WinBUGS}} + \item{useWINE}{as in \code{\link{bugs}} meta function} + \item{newWINE}{as in \code{\link{bugs}} meta function} + \item{WINEPATH}{as in \code{\link{bugs}} meta function} } \value{Nothing, but as a side effect, the script file \file{script.txt} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |