From: <li...@us...> - 2007-05-13 16:49:33
|
Revision: 17 http://svn.sourceforge.net/bugs-r/?rev=17&view=rev Author: ligges Date: 2007-05-13 09:49:34 -0700 (Sun, 13 May 2007) Log Message: ----------- The codetools checks revealed quite a lot of bugs and inconsistencies. Unfortunately we cannot make codetools calm since codetools do not expect S-PLUS. Again, prepared for release. Modified Paths: -------------- trunk/R2WinBUGS/Changes trunk/R2WinBUGS/DESCRIPTION trunk/R2WinBUGS/R/attach.all.R trunk/R2WinBUGS/R/bugs.R trunk/R2WinBUGS/R/bugs.data.R trunk/R2WinBUGS/R/bugs.run.R trunk/R2WinBUGS/R/bugs.script.R trunk/R2WinBUGS/R/bugs.update.settings.R trunk/R2WinBUGS/R/openbugs.R trunk/R2WinBUGS/R/read.bugs.R trunk/R2WinBUGS/R/wineutils.R trunk/R2WinBUGS/R/write.model.R trunk/R2WinBUGS/man/bugs.run.Rd Modified: trunk/R2WinBUGS/Changes =================================================================== --- trunk/R2WinBUGS/Changes 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/Changes 2007-05-13 16:49:34 UTC (rev 17) @@ -70,5 +70,7 @@ - print.bugs / plot.bugs documentation fixes - write.model() fix -Update 2.1-2 (12 May 2007): +Update 2.1-3 (13 May 2007): - Ported to S-PLUS by Insightful Corp. +- some fixes for codetools checks + Modified: trunk/R2WinBUGS/DESCRIPTION =================================================================== --- trunk/R2WinBUGS/DESCRIPTION 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/DESCRIPTION 2007-05-13 16:49:34 UTC (rev 17) @@ -1,7 +1,7 @@ Package: R2WinBUGS Title: Running WinBUGS and OpenBUGS from R / S-PLUS -Date: 2007-05-12 -Version: 2.1-2 +Date: 2007-05-13 +Version: 2.1-3 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/attach.all.R =================================================================== --- trunk/R2WinBUGS/R/attach.all.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/attach.all.R 2007-05-13 16:49:34 UTC (rev 17) @@ -29,10 +29,7 @@ detach("bugs.sims")} x$sims.list$n.sims <- x$n.sims # put n.sims into sims.list for convenience r2 <- attach.all(x$sims.list, overwrite = overwrite, name = "bugs.sims") - if (is.R()) - invisible (bugs.sims = r2) - else - invisible (r2) + invisible (r2) } detach.all <- function(name = "attach.all"){ Modified: trunk/R2WinBUGS/R/bugs.R =================================================================== --- trunk/R2WinBUGS/R/bugs.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/bugs.R 2007-05-13 16:49:34 UTC (rev 17) @@ -60,7 +60,7 @@ bugs.script(parameters.to.save, n.chains, n.iter, n.burnin, n.thin, new.model.file, debug=debug, is.inits=!is.null(inits), bin = bin, DIC = DIC, useWINE = useWINE, newWINE = newWINE, WINEPATH = WINEPATH) - bugs.run(n.burnin, bugs.directory, WINE = WINE, useWINE = useWINE) + bugs.run(n.burnin, bugs.directory, WINE = WINE, useWINE = useWINE, WINEPATH = WINEPATH) if(codaPkg) return(file.path(getwd(), paste("coda", 1:n.chains, ".txt", sep=""))) Modified: trunk/R2WinBUGS/R/bugs.data.R =================================================================== --- trunk/R2WinBUGS/R/bugs.data.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/bugs.data.R 2007-05-13 16:49:34 UTC (rev 17) @@ -1,29 +1,28 @@ "bugs.data" <- function(data, dir = getwd(), digits = 5){ if(is.numeric(unlist(data))) - if(is.R()) { - write.datafile(lapply(data, formatC, digits = digits, format = "E"), - file.path(dir, "data.txt")) - } - else { - writeDatafileS4(data, towhere = "data.txt") - } + if(is.R()) { + write.datafile(lapply(data, formatC, digits = digits, format = "E"), + file.path(dir, "data.txt")) + } + else { + writeDatafileS4(data, towhere = "data.txt") + } else { - if(is.R()) { - data.list <- lapply(as.list(data), get, pos = parent.frame(2)) - names(data.list) <- as.list(data) - write.datafile(lapply(data.list, formatC, digits = digits, format = "E"), - file.path(dir, "data.txt")) - } - else { - data.list <- lapply(as.list(data), get, where = parent.frame(2)) - names(data.list) <- unlist(data) - writeDatafileS4(data.list, towhere = "data.txt") - } - } + if(is.R()) { + data.list <- lapply(as.list(data), get, pos = parent.frame(2)) + names(data.list) <- as.list(data) + write.datafile(lapply(data.list, formatC, digits = digits, format = "E"), + file.path(dir, "data.txt")) + } + else { + data.list <- lapply(as.list(data), get, where = parent.frame(2)) + names(data.list) <- unlist(data) + writeDatafileS4(data.list, towhere = "data.txt") + } + } } -if (!is.R()) { "writeDatafileS4" <- # @@ -50,128 +49,128 @@ # Revision history: 2002-11-19. Fixed to handle missing values properly. function(DATA, towhere = "clipboard", fill = TRUE) { - formatDataS4 = - # - # Prepared DATA for input to WinBUGS. - function(DATA) - { - if(!is.list(DATA)) - stop("DATA must be a named list or data frame.") - dlnames <- names(DATA) - if(is.data.frame(DATA)) - DATA <- as.list(DATA) - # - # Checking for lists in DATA.... - lind <- sapply(DATA, is.list) - # Checking for data frames in DATA.... - dfind <- sapply(DATA, is.data.frame) - # Any lists that are not data frames?... - if(any(lind & !dfind)) stop("DATA may not contain lists.") - # Checking for unnamed elements of list that are not data frames.... - if(any(dlnames[!dfind] == "")) stop( - "When DATA is a list, all its elements that are not data frames must be named." - ) - # Checking for duplicate names.... - dupnames <- unique(dlnames[duplicated(dlnames)]) - if(length(dupnames) > 0) - stop(paste( - "The following names are used more than once in DATA:", - paste(dupnames, collapse = ", "))) - if(any(dfind)) { - dataold <- DATA - DATA <- vector("list", 0) - for(i in seq(along = dataold)) { - if(dfind[i]) - DATA <- c(DATA, as.list(dataold[[i]])) - else DATA <- c(DATA, dataold[i]) - } - dataold <- NULL - } - dlnames <- names(DATA) - dupnames <- unique(dlnames[duplicated(dlnames)]) - # Checking for duplicated names again (now that columns of data frames are included).... - if(length(dupnames) > 0) stop(paste( - "The following names are used more than once in DATA (at least once within a data frame):", - paste(dupnames, collapse = ", "))) - # Checking for factors.... - factorind <- sapply(DATA, is.factor) - if(any(factorind)) - stop(paste( - "DATA may not include factors. One or more factor variables were detected:", - paste(dlnames[factorind], collapse = ", "))) - # Checking for character vectors.... - charind <- sapply(DATA, is.character) - if(any(charind)) - stop(paste( - "WinBUGS does not handle character data. One or more character variables were detected:", - paste(dlnames[charind], collapse = ", "))) - # Checking for complex vectors.... - complexind <- sapply(DATA, is.complex) - if(any(complexind)) - stop(paste( - "WinBUGS does not handle complex data. One or more complex variables were detected:", - paste(dlnames[complexind], collapse = ", "))) - # Checking for values farther from zero than 1E+38 (which is limit of single precision).... - toobigind <- sapply(DATA, function(x) - { - y <- abs(x[!is.na(x)]) - any(y[y > 0] > 9.9999999999999998e+37) - } - ) - if(any(toobigind)) - stop(paste( - "WinBUGS works in single precision. The following variables contain data outside the range +/-1.0E+38: ", - paste(dlnames[toobigind], collapse = ", "), - ".\n", sep = "")) - # Checking for values in range +/-1.0E-38 (which is limit of single precision).... - toosmallind <- sapply(DATA, function(x) - { - y <- abs(x[!is.na(x)]) - any(y[y > 0] < 9.9999999999999996e-39) - } - ) - n <- length(dlnames) - data.string <- as.list(rep(NA, n)) - for(i in 1:n) { - if(length(DATA[[i]]) == 1) { - ac <- toSingleS4(DATA[[i]]) - data.string[[i]] <- paste(names(DATA)[i], "=", - ac, sep = "") - next - } - if(is.vector(DATA[[i]]) & length(DATA[[i]]) > 1) { - ac <- toSingleS4(DATA[[i]]) - data.string[[i]] <- paste(names(DATA)[i], "=c(", - paste(ac, collapse = ", "), ")", sep = - "") - next - } - if(is.array(DATA[[i]])) { - ac <- toSingleS4(aperm(DATA[[i]])) - data.string[[i]] <- paste(names(DATA)[i], - "= structure(.Data= c(", paste(ac, - collapse = ", "), "), \n .Dim=c(", - paste(as.character(dim(DATA[[i]])), - collapse = ", "), "))", sep = "") - } - } - data.tofile <- paste("list(", paste(unlist(data.string), - collapse = ", "), ")", sep = "") - if(any(toosmallind)) - warning(paste( - "WinBUGS works in single precision. The following variables contained nonzero data", - "\ninside the range +/-1.0E-38 that were set to zero: ", - paste(dlnames[toosmallind], collapse = ", "), - ".\n", sep = "")) - return(data.tofile) - } - rslt <- formatDataS4(DATA) - cat(rslt, file = towhere, fill = fill) - invisible(0) + formatDataS4 = + # + # Prepared DATA for input to WinBUGS. + function(DATA) + { + if(!is.list(DATA)) + stop("DATA must be a named list or data frame.") + dlnames <- names(DATA) + if(is.data.frame(DATA)) + DATA <- as.list(DATA) + # + # Checking for lists in DATA.... + lind <- sapply(DATA, is.list) + # Checking for data frames in DATA.... + dfind <- sapply(DATA, is.data.frame) + # Any lists that are not data frames?... + if(any(lind & !dfind)) stop("DATA may not contain lists.") + # Checking for unnamed elements of list that are not data frames.... + if(any(dlnames[!dfind] == "")) stop( + "When DATA is a list, all its elements that are not data frames must be named." + ) + # Checking for duplicate names.... + dupnames <- unique(dlnames[duplicated(dlnames)]) + if(length(dupnames) > 0) + stop(paste( + "The following names are used more than once in DATA:", + paste(dupnames, collapse = ", "))) + if(any(dfind)) { + dataold <- DATA + DATA <- vector("list", 0) + for(i in seq(along = dataold)) { + if(dfind[i]) + DATA <- c(DATA, as.list(dataold[[i]])) + else DATA <- c(DATA, dataold[i]) + } + dataold <- NULL + } + dlnames <- names(DATA) + dupnames <- unique(dlnames[duplicated(dlnames)]) + # Checking for duplicated names again (now that columns of data frames are included).... + if(length(dupnames) > 0) stop(paste( + "The following names are used more than once in DATA (at least once within a data frame):", + paste(dupnames, collapse = ", "))) + # Checking for factors.... + factorind <- sapply(DATA, is.factor) + if(any(factorind)) + stop(paste( + "DATA may not include factors. One or more factor variables were detected:", + paste(dlnames[factorind], collapse = ", "))) + # Checking for character vectors.... + charind <- sapply(DATA, is.character) + if(any(charind)) + stop(paste( + "WinBUGS does not handle character data. One or more character variables were detected:", + paste(dlnames[charind], collapse = ", "))) + # Checking for complex vectors.... + complexind <- sapply(DATA, is.complex) + if(any(complexind)) + stop(paste( + "WinBUGS does not handle complex data. One or more complex variables were detected:", + paste(dlnames[complexind], collapse = ", "))) + # Checking for values farther from zero than 1E+38 (which is limit of single precision).... + toobigind <- sapply(DATA, function(x) + { + y <- abs(x[!is.na(x)]) + any(y[y > 0] > 9.9999999999999998e+37) + } + ) + if(any(toobigind)) + stop(paste( + "WinBUGS works in single precision. The following variables contain data outside the range +/-1.0E+38: ", + paste(dlnames[toobigind], collapse = ", "), + ".\n", sep = "")) + # Checking for values in range +/-1.0E-38 (which is limit of single precision).... + toosmallind <- sapply(DATA, function(x) + { + y <- abs(x[!is.na(x)]) + any(y[y > 0] < 9.9999999999999996e-39) + } + ) + n <- length(dlnames) + data.string <- as.list(rep(NA, n)) + for(i in 1:n) { + if(length(DATA[[i]]) == 1) { + ac <- toSingleS4(DATA[[i]]) + data.string[[i]] <- paste(names(DATA)[i], "=", + ac, sep = "") + next + } + if(is.vector(DATA[[i]]) & length(DATA[[i]]) > 1) { + ac <- toSingleS4(DATA[[i]]) + data.string[[i]] <- paste(names(DATA)[i], "=c(", + paste(ac, collapse = ", "), ")", sep = + "") + next + } + if(is.array(DATA[[i]])) { + ac <- toSingleS4(aperm(DATA[[i]])) + data.string[[i]] <- paste(names(DATA)[i], + "= structure(.Data= c(", paste(ac, + collapse = ", "), "), \n .Dim=c(", + paste(as.character(dim(DATA[[i]])), + collapse = ", "), "))", sep = "") + } + } + data.tofile <- paste("list(", paste(unlist(data.string), + collapse = ", "), ")", sep = "") + if(any(toosmallind)) + warning(paste( + "WinBUGS works in single precision. The following variables contained nonzero data", + "\ninside the range +/-1.0E-38 that were set to zero: ", + paste(dlnames[toosmallind], collapse = ", "), + ".\n", sep = "")) + return(data.tofile) + } + rslt <- formatDataS4(DATA) + cat(rslt, file = towhere, fill = fill) + invisible(0) } -toSingleS4 = +toSingleS4 <- # # Takes numeric vector and removes digit of exponent in scientific notation (if any) # @@ -180,50 +179,48 @@ # Revision history: 2002-11-19. Fixed to handle missing values properly. function(x) { - xdim <- dim(x) - x <- as.character(as.single(x)) + xdim <- dim(x) + x <- as.character(as.single(x)) - # First to look for positives: - pplus <- regMatchPos(x, "e\\+0") - pplusind <- apply(pplus, 1, function(y) - (!any(is.na(y)))) - if(any(pplusind)) { - # Making sure that periods are in mantissa... - init <- substring(x[pplusind], 1, pplus[ - pplusind, 1] - 1) - #...preceeding exponent - pper <- regMatchPos(init, "\\.") - pperind <- apply(pper, 1, function(y) - (all(is.na(y)))) - if(any(pperind)) - init[pperind] <- paste(init[pperind], - ".0", sep = "") - # Changing the format of the exponent... - x[pplusind] <- paste(init, "E+", substring( - x[pplusind], pplus[pplusind, 2] + 1), - sep = "") - } - # Then to look for negatives: - pminus <- regMatchPos(x, "e\\-0") - pminusind <- apply(pminus, 1, function(y) - (!any(is.na(y)))) - if(any(pminusind)) { - # Making sure that periods are in mantissa... - init <- substring(x[pminusind], 1, pminus[ - pminusind, 1] - 1) - #...preceeding exponent - pper <- regMatchPos(init, "\\.") - pperind <- apply(pper, 1, function(y) - (all(is.na(y)))) - if(any(pperind)) - init[pperind] <- paste(init[pperind], - ".0", sep = "") - # Changing the format of the exponent... - x[pminusind] <- paste(init, "E-", substring( - x[pminusind], pminus[pminusind, 2] + - 1), sep = "") - } - x + # First to look for positives: + pplus <- regMatchPos(x, "e\\+0") + pplusind <- apply(pplus, 1, function(y) + (!any(is.na(y)))) + if(any(pplusind)) { + # Making sure that periods are in mantissa... + init <- substring(x[pplusind], 1, pplus[ + pplusind, 1] - 1) + #...preceeding exponent + pper <- regMatchPos(init, "\\.") + pperind <- apply(pper, 1, function(y) + (all(is.na(y)))) + if(any(pperind)) + init[pperind] <- paste(init[pperind], + ".0", sep = "") + # Changing the format of the exponent... + x[pplusind] <- paste(init, "E+", substring( + x[pplusind], pplus[pplusind, 2] + 1), + sep = "") + } + # Then to look for negatives: + pminus <- regMatchPos(x, "e\\-0") + pminusind <- apply(pminus, 1, function(y) + (!any(is.na(y)))) + if(any(pminusind)) { + # Making sure that periods are in mantissa... + init <- substring(x[pminusind], 1, pminus[ + pminusind, 1] - 1) + #...preceeding exponent + pper <- regMatchPos(init, "\\.") + pperind <- apply(pper, 1, function(y) + (all(is.na(y)))) + if(any(pperind)) + init[pperind] <- paste(init[pperind], + ".0", sep = "") + # Changing the format of the exponent... + x[pminusind] <- paste(init, "E-", substring( + x[pminusind], pminus[pminusind, 2] + + 1), sep = "") + } + x } - -} # ends if (!is.R()) Modified: trunk/R2WinBUGS/R/bugs.run.R =================================================================== --- trunk/R2WinBUGS/R/bugs.run.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/bugs.run.R 2007-05-13 16:49:34 UTC (rev 17) @@ -1,6 +1,7 @@ "bugs.run" <- function(n.burnin, bugs.directory, WINE = "", - useWINE = .Platform$OS.type != "windows", newWINE = TRUE){ + 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") @@ -26,7 +27,7 @@ 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), + native2win(file.path(getwd(), "script.txt"), newWINE = newWINE, WINEPATH = WINEPATH), "\"", sep = "") if (useWINE) bugsCall <- paste(WINE, bugsCall) Modified: trunk/R2WinBUGS/R/bugs.script.R =================================================================== --- trunk/R2WinBUGS/R/bugs.script.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/bugs.script.R 2007-05-13 16:49:34 UTC (rev 17) @@ -17,7 +17,8 @@ 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=""), native2win) + inits <- sapply(paste(working.directory, "/inits", 1:n.chains, ".txt", sep=""), + function(x) native2win(x, , 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)) @@ -34,15 +35,15 @@ ## Therefore, if the samples are read into S-PLUS using the coda package, ## the thinning will be correctly labelled in the resulting mcmc object. ## In R, the thinning is always labelled as 1, even if thinning was done. - thinUpdateCommand <- paste("update (", n.burnin, ")\n", - "thin.samples (", n.thin, ")\n", sep = "") - bin = bin * n.thin + thinUpdateCommand <- paste("update (", n.burnin, ")\n", + "thin.samples (", n.thin, ")\n", sep = "") + bin = bin * n.thin } cat( "display ('log')\n", - "check ('", native2win(model), "')\n", - "data ('", native2win(data), "')\n", + "check ('", native2win(model, WINEPATH=WINEPATH), "')\n", + "data ('", native2win(data, WINEPATH=WINEPATH), "')\n", "compile (", n.chains, ")\n", if(is.inits) initlist, "gen.inits()\n", @@ -51,12 +52,12 @@ if(DIC) "dic.set()\n", rep( c("update (", formatC(ceiling(bin), format = "d"), ")\n", - "coda (*, '", native2win(coda), "')\n"),redo), + "coda (*, '", native2win(coda, WINEPATH=WINEPATH), "')\n"),redo), "stats (*)\n", if(DIC) "dic.stats()\n", - "history (*, '", native2win(history), "')\n", - "save ('", native2win(logfile), "')\n", - "save ('", native2win(logfileTxt), "')\n", + "history (*, '", native2win(history, WINEPATH=WINEPATH), "')\n", + "save ('", native2win(logfile, WINEPATH=WINEPATH), "')\n", + "save ('", native2win(logfileTxt, WINEPATH=WINEPATH), "')\n", file=script, sep="", append=FALSE) if (!debug) cat ("quit ()\n", file=script, append=TRUE) sims.files <- paste ("coda", 1:n.chains, ".txt", sep="") Modified: trunk/R2WinBUGS/R/bugs.update.settings.R =================================================================== --- trunk/R2WinBUGS/R/bugs.update.settings.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/bugs.update.settings.R 2007-05-13 16:49:34 UTC (rev 17) @@ -1,13 +1,13 @@ "bugs.update.settings" <- function (n.burnin, bugs.directory){ - + char.burnin <- as.character(n.burnin - 1) - if (is.R()){ - file.copy(file.path(bugs.directory, "System/Rsrc/Registry.odc"), + if (is.R()){ + file.copy(file.path(bugs.directory, "System/Rsrc/Registry.odc"), file.path(bugs.directory, "System/Rsrc/Registry_Rsave.odc"), overwrite = TRUE) } else { - splus.file.copy(file.path(bugs.directory, "System/Rsrc/Registry.odc"), + splus.file.copy(file.path(bugs.directory, "System/Rsrc/Registry.odc"), file.path(bugs.directory, "System/Rsrc/Registry_Rsave.odc"), overwrite = TRUE) } @@ -15,19 +15,19 @@ "character", 400, size = 1, endian = "little") locale <- Sys.getlocale("LC_CTYPE") Sys.setlocale("LC_CTYPE", "C") - if (is.R()) - info <- registry[regexpr("Int", registry, fixed = TRUE, useBytes = TRUE) > 0] - else - info <- registry[regexpr("Int", registry, fixed = TRUE) > 0] + if (is.R()) + info <- registry[regexpr("Int", registry, fixed = TRUE, useBytes = TRUE) > 0] + else + info <- registry[regexpr("Int", registry, fixed = TRUE) > 0] while(regexpr("\r", info) > 0){ newline <- regexpr("\r", info) info <- substring(info, newline + 1) line <- substring(info, 1, regexpr("\r", info) - 1) if(regexpr("AdaptivePhase", line) > 0){ if (is.R()) - numpos <- regexpr("Int", line, fixed = TRUE, useBytes = TRUE) + 4 + numpos <- regexpr("Int", line, fixed = TRUE, useBytes = TRUE) + 4 else - numpos <- regexpr("Int", line, fixed = TRUE) + 4 + numpos <- regexpr("Int", line, fixed = TRUE) + 4 num <- substring(line, numpos) if (as.numeric(num) > n.burnin){ @@ -43,8 +43,6 @@ file.path(bugs.directory, "System/Rsrc/Registry.odc"), endian = "little") } -if (!is.R()){ - "splus.file.copy"<- function(from, to, overwrite = FALSE) { @@ -57,5 +55,3 @@ size = 1) invisible(z) } - -} #ends if (!is.R()) Modified: trunk/R2WinBUGS/R/openbugs.R =================================================================== --- trunk/R2WinBUGS/R/openbugs.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/openbugs.R 2007-05-13 16:49:34 UTC (rev 17) @@ -33,43 +33,43 @@ model <- readLines(modelFile) try(writeLines(model, modelFile)) } - modelCheck(modelFile) + BRugs::modelCheck(modelFile) if(!(is.vector(data) && is.character(data) && all(file.exists(data)))) { - data <- bugsData(data, digits = digits) + data <- BRugs::bugsData(data, digits = digits) } - modelData(data) - modelCompile(numChains) + BRugs::modelData(data) + BRugs::modelCompile(numChains) if(missing(inits) || is.null(inits)) { - modelGenInits() + BRugs::modelGenInits() } else { if(is.list(inits) || is.function(inits) || (is.character(inits) && !any(file.exists(inits)))){ - inits <- bugsInits(inits = inits, numChains = numChains, digits = digits) + inits <- BRugs::bugsInits(inits = inits, numChains = numChains, digits = digits) } - modelInits(inits) - modelGenInits() + BRugs::modelInits(inits) + BRugs::modelGenInits() } - samplesSetThin(nThin) + BRugs::samplesSetThin(nThin) # set the adaptive phases adaptivelines <- scan(system.file("OpenBUGS", "Bugs", "Rsrc", "Registry.txt", package="BRugs"), what="character") factories <- sub(".adaptivePhase", "", adaptivelines[grep("adaptivePhase",adaptivelines)]) - sapply(factories, modelSetAP, max(0, nBurnin-1)) + sapply(factories, BRugs::modelSetAP, max(0, nBurnin-1)) - modelUpdate(nBurnin) + BRugs::modelUpdate(nBurnin) if(!is.null(DIC)) { - dicSet() - on.exit(dicClear(), add = TRUE) + BRugs::dicSet() + on.exit(BRugs::dicClear(), add = TRUE) } - samplesSet(parametersToSave) - modelUpdate(nIter) - params <- sort.name(samplesMonitors("*"), parametersToSave) - samples <- sapply(params, samplesSample) + BRugs::samplesSet(parametersToSave) + BRugs::modelUpdate(nIter) + params <- sort.name(BRugs::samplesMonitors("*"), parametersToSave) + samples <- sapply(params, BRugs::samplesSample) n.saved.per.chain <- nrow(samples)/numChains samples.array <- array(samples, c(n.saved.per.chain, numChains, ncol(samples))) dimnames(samples.array)[[3]] <- dimnames(samples)[[2]] - if(!is.null(DIC)) DIC <- dicStats() + if(!is.null(DIC)) DIC <- BRugs::dicStats() bugs.output <- as.bugs.array(samples.array, modelFile, program="OpenBUGS", n.iter=n.iter, n.burnin=n.burnin, n.thin=n.thin, DIC=DIC) return(bugs.output) Modified: trunk/R2WinBUGS/R/read.bugs.R =================================================================== --- trunk/R2WinBUGS/R/read.bugs.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/read.bugs.R 2007-05-13 16:49:34 UTC (rev 17) @@ -1,7 +1,7 @@ read.bugs <- function(codafiles, ...){ if(!require(coda)) stop("package 'coda' is required to use this function") - mcmc.list(lapply(codafiles, read.coda, + coda::mcmc.list(lapply(codafiles, coda::read.coda, index.file = file.path(dirname(codafiles[1]), "codaIndex.txt"), ...)) } Modified: trunk/R2WinBUGS/R/wineutils.R =================================================================== --- trunk/R2WinBUGS/R/wineutils.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/wineutils.R 2007-05-13 16:49:34 UTC (rev 17) @@ -52,7 +52,7 @@ } # end if (is.R()) -native2win <- function(x, useWINE=.Platform$OS.type != "windows", newWINE=TRUE) { # native -> win +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) { Modified: trunk/R2WinBUGS/R/write.model.R =================================================================== --- trunk/R2WinBUGS/R/write.model.R 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/R/write.model.R 2007-05-13 16:49:34 UTC (rev 17) @@ -21,8 +21,6 @@ writeLines(model.text, con = con) } -if (!is.R()){ - replaceScientificNotation <- function(text){ ## Change the format of any numbers in "text" that are in S-PLUS ## scientific notation to WinBUGS scientific notation @@ -31,7 +29,7 @@ ## Find the first instance ## Note that the number may or may not have a decimal point. sciNoteLoc <- regexpr("[0-9]*\\.{0,1}[0-9]*e\\+0[0-9]{2}", text) - + ## For every instance, replace the number while(sciNoteLoc > -1){ sciNoteEnd <- sciNoteLoc + attr(sciNoteLoc, "match.length")-1 @@ -54,4 +52,3 @@ text } -} ## ends if (!is.R()) Modified: trunk/R2WinBUGS/man/bugs.run.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.run.Rd 2007-05-13 11:43:49 UTC (rev 16) +++ trunk/R2WinBUGS/man/bugs.run.Rd 2007-05-13 16:49:34 UTC (rev 17) @@ -6,7 +6,8 @@ calls WinBUGS and runs it with \file{script.txt}. Intended for internal use only} \usage{ bugs.run(n.burnin, bugs.directory, WINE = "", - useWINE = .Platform$OS.type != "windows", newWINE = TRUE) + useWINE = .Platform$OS.type != "windows", + newWINE = TRUE, WINEPATH = NULL) } \arguments{ \item{n.burnin}{length of burn in} @@ -16,6 +17,8 @@ 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.} } \value{ Does not return anything. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |