[R] Making R talk to Win/OpenBUGS in Linux (again)

Paul Johnson pauljohn32 at gmail.com
Sun Apr 30 23:22:35 CEST 2006


Thank you very much.  With the insertion of WINEPATH declaration, then
the following example program does run.  And really fast, too!





library(R2WinBUGS)

WINEPATH <- "/usr/bin/winepath"

                                        # An example model file is given in:
model.file <- system.file(package = "R2WinBUGS", "model", "schools.txt")
# Let's take a look:
file.show(model.file)

# Some example data (see ?schools for details):
data(schools)
schools

J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list ("J", "y", "sigma.y")
inits <- function(){
    list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100),
        sigma.theta = runif(1, 0, 100))
}
parameters <- c("theta", "mu.theta", "sigma.theta")


schools.sim <- bugs(data, inits, parameters, model.file, n.chains = 3,
n.iter = 1000,bugs.directory = "/usr/local/share/WinBUGS14/",
working.directory = "/tmp", clearWD = FALSE, useWINE=T, newWINE=T,
WINE="/usr/bin/wine",WINEPATH=WINEPATH)




On 4/30/06, Gregor Gorjanc <gregor.gorjanc at gmail.com> wrote:
> Hello Paul,
>
> thank you very much for this report. You caught a bug in R2WinBUGS that
> was introduced by me. I added support for winepath in 1.1-1 version.
> Since I switch between Windows and Linux I always set WINEPATH and then
> use it in bugs(). That's why I forgot to add it in further calls in
> bugs(). How silly :( This actually means that nobody else beside you
> tried to run R2WinBUGS under Linux. To bad. Please report summary to
> BUGS list as you have also asked there for help and I did not had time
> to answer you. I have been successfully running R2WinBUGS under Linux
> for quite some time now.
>
> Now you have the following options:
>
> A Set WINEPATH before you call bugs()
>
> i.e.
>
> WINEPATH <- "/usr/bin/winepath"
>
> bugs(..., WINEPATH=WINEPATH)
>
> This is the fastest approach for you.
>
> B Apply the following diffs, build and install R2WinBUGS by yourself
>
> I am also sendind them to maintainer of the package. So this should be
> fixed soon also on CRAN. Uwe?
>
> --- R2WinBUGSOrig/R/bugs.R      2006-04-29 21:44:59.000000000 +0200
> +++ R2WinBUGS/R/bugs.R  2006-04-30 12:52:36.000000000 +0200
> @@ -44,7 +44,7 @@
>    } else new.model.file <- model.file
>    bugs.script(parameters.to.save, n.chains, n.iter, n.burnin, n.thin,
>      bugs.directory, new.model.file, debug=debug, is.inits=!is.null(inits),
> -    bin = bin, DIC = DIC, useWINE = useWINE, newWINE = newWINE)
> +    bin = bin, DIC = DIC, useWINE = useWINE, newWINE = newWINE,
> WINEPATH=WINEPATH)
>    #if (useWINE && missing(bugs.directory))
>    #  bugs.directory <- winedriveTr(bugs.directory)
>    bugs.run(n.burnin, bugs.directory, WINE = WINE)
>
> --- R2WinBUGSOrig/R/bugs.script.R       2006-04-29 21:44:59.000000000 +0200
> +++ R2WinBUGS/R/bugs.script.R   2006-04-30 12:52:12.000000000 +0200
> @@ -1,7 +1,7 @@
>  "bugs.script" <-
>  function (parameters.to.save, n.chains, n.iter, n.burnin,
>      n.thin, bugs.directory, model.file, debug=FALSE, is.inits, bin,
> -    DIC = FALSE, useWINE = FALSE, newWINE = FALSE){
> +    DIC = FALSE, useWINE = FALSE, newWINE = FALSE, WINEPATH=NULL){
>
> > I'm back!
> >
> > I've just learned that, on a fully updated Fedora Core Linux5 sytem,
> > the working solution to access Winbugs under wine via the R package
> > "rbugs" no longer works.  Here was my last post on this topic (with
> > the formerly working solution) from January.
> >
> > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/68497.html
> >
> > Currently, what happens is that WinBUGS starts up, but just sits there
> > doing nothing.  I do not know if the problem is due to a change in
> > wine or rbugs, and since both of them are updated, it is hard to say.
> > I'm thinking it is a wine or perhaps even a kernel related problem.
> > Inside WinBUGS running under wine, it does not even work to manually
> > open the bugs.script file and then choose "Model/Script".  it just
> > returns a screen full of errors saying the commands fail.  I don't
> > think rbugs gets even that far, however, since the WinBUGS window does
> > pop up, but nothing happens.
> >
> > rbugs has been retooled to emphasize use of linbugs, the
> > OpenBUGS-based thing for linux, but I can't get linbugs to run at all
> > on my system, and the linbugs program itself appears to have been
> > removed from OpenBUGS distribution altogether. (I'm following that
> > with separate email to the OpenBUGS group).
> >
> > I think JAGS is the right long term solution, but currently I'm in the
> > middle of a semester trying to teach about Bayesian stats and the
> > students have some familiarity with WinBUGS and I'm interested in
> > making it work. So while I'm learning more about JAGS and the bayesmix
> > package that supports access to it from R, I still would like a way to
> > interact with Winbugs through Wine.
> >
> > If anybody has rbugs working in current Linux, please tell me
> > how--give me a working example?
> >
> > In the meanwhile, I've noticed that nightly updates have successfully
> > installed R2WinBUGS on linux systems and I've got a small test case
> > that I'd like to ask about.  Since rbugs is a linux adaptation of
> > R2WinBUGS, and R2WinBUGS is now buildable on Linux, it looks like
> > R2WinBUGS may be the way to go.  But it fails.  The error centers
> > around the "WINEPATH" setting.  I've learned that wine has a function
> > "winepath" that returns information that programs can use, and I've
> > fiddled this lots of ways, but it fails, saying
> >
> >
> > Error in paste(WINEPATH, "-w", x) : object "WINEPATH" not found
> > library(R2WinBUGS)
> >
> > I hope that by giving you this small not-yet-working example, you can
> > spot where I'm going wrong.
> >
> > ##Paul Johnson 2006-04-29
> >
> >
> > library(R2WinBUGS)
> > # Copied from Prof Andrew Gelman's example
> > model.file <- system.file(package = "R2WinBUGS", "model", "schools.txt")
> > #
> > file.show(model.file)
> > data(schools)
> > schools
> >
> > J <- nrow(schools)
> > y <- schools$estimate
> > sigma.y <- schools$sd
> > data <- list ("J", "y", "sigma.y")
> > inits <- function(){
> >     list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100),
> >         sigma.theta = runif(1, 0, 100))
> > }
> > parameters <- c("theta", "mu.theta", "sigma.theta")
> >
> >
> > schools.sim <- bugs(data, inits, parameters, model.file, n.chains = 3,
> > n.iter = 1000,bugs.directory = "/usr/local/share/WinBUGS14/",
> > working.directory = "/tmp", clearWD = FALSE, useWINE=T, newWINE=T,
> > WINE="/usr/bin/wine",WINEPATH="/usr/bin/winepath")
> >
> >
> >
> > I do have the binary "/usr/bin/winepath", but can't tell how to give
> > R2WinBUGS what it wants.  Many failed efforts below:
> >
> >
> >
> >>> schools.sim <- bugs(data, inits, parameters, model.file, n.chains = 3, n.iter = 1000,bugs.directory = "/usr/local/share/WinBUGS14/", working.directory = "/tmp", clearWD = FALSE, useWINE=T, newWINE=T, WINE="/usr/bin/wine",WINEPATH="/usr/bin/")
> >
> > Error in paste(WINEPATH, "-w", x) : object "WINEPATH" not found
> >
> >>> schools.sim <- bugs(data, inits, parameters, model.file, n.chains = 3, n.iter = 1000,bugs.directory = "/usr/local/share/WinBUGS14/", working.directory = "/tmp", clearWD = FALSE, useWINE=T, newWINE=T, WINE="/usr/bin/wine")
> >
> > Error in if (!nchar(WINEPATH)) { : argument is of length zero
> >
> >>> schools.sim <- bugs(data, inits, parameters, model.file, n.chains = 3, n.iter = 1000,bugs.directory = "/usr/local/share/WinBUGS14/", working.directory = "/tmp", clearWD = FALSE, useWINE=T, newWINE=T, WINE="/usr/bin/wine",WINEPATH="/usr/bin")
> >
> > Error in paste(WINEPATH, "-w", x) : object "WINEPATH" not found
> >
> >>>
> >
> >
> > I know there are many unknowns here, but hope somebody has at least
> > one working example that we can build on.
>
>
> --
> Lep pozdrav / With regards,
>     Gregor Gorjanc
>
> ----------------------------------------------------------------------
> University of Ljubljana     PhD student
> Biotechnical Faculty
> Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
> Groblje 3                   mail: gregor.gorjanc <at> bfro.uni-lj.si
>
> SI-1230 Domzale             tel: +386 (0)1 72 17 861
> Slovenia, Europe            fax: +386 (0)1 72 17 888
>
> ----------------------------------------------------------------------
> "One must learn by doing the thing; for though you think you know it,
>  you have no certainty until you try." Sophocles ~ 450 B.C.
> ----------------------------------------------------------------------
>
>
>


--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas




More information about the R-help mailing list