swh:1:snp:cb3ee08893d9ebea95d32b41026209106231a62e
Raw File
Tip revision: 0faae5d1bebb806f74787c60e11bbdf92d822c8d authored by Sibylle Sturtz on 26 May 2006, 00:00:00 UTC
version 2.0-1
Tip revision: 0faae5d
bugs.run.R
"bugs.run" <-
    function(n.burnin, bugs.directory, WINE = "", 
             useWINE = .Platform$OS.type != "windows", newWINE = TRUE){

if(useWINE && !newWINE) bugs.directory <- win2native(bugs.directory)

## 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
  on.exit(try(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)) 
    stop(paste("WinBUGS executable does not exist in", bugs.directory))
## Call Bugs and have it run with script.txt
  bugsCall <- paste("\"", dos.location, "\" /par \"",
                    native2win(file.path(getwd(), "script.txt"), newWINE = newWINE),
                    "\"", 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.")
## Stop and print an error message if Bugs did not run correctly
  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.")
}


 
back to top