OpenBugs allows you to provide input data through an S-PLUS data structure or the so-called rectangular format. The S-PLUS format is arguably the most commonly used and it is quite easy to implement. For instance, one can add data related to a random variable X, including the size of this variable (n) as follows:
list(x=c(3.4, 4.5, 6.7, 8.9), n=4)
The problem is that when working with multivariate statistics and large data sets, typing each value in a list can be time consuming and cumbersome. I find that a very effective way around this is to export data from R into OpenBugs using this very practical (and flexible) R script called writeDatafileR.txt from Iowa State University or here.
So, let's say I want to use some data from R and then create an input file to be used in OpenBugs. Here's an example of how this could be done. It assumes you have downloaded the writeDatafileR.txt script and that it is located in your R current directory. Then from R, we would type:
# First we source the script you downloaded
source("writeDatafileR.txt")
# Then we create a mock data set as an example: 500 samples from a normal distribution
# The distribution is X~N(20,42)
x=rnorm(500,20,4)
# We also draw 500 samples to create another data set, just to illustrate
# Y~N(17.3,52)
y=rnorm(500,17.3,5)
# First, we create a dataframe to house the x and y variables we created above
w=data.frame(cbind(x,y))
# Finally, we can use writeDatafileR.txt
writeDatafileR(w,"DatatoOpenBugs.txt")
This will create a file called 'DatatoOpenBugs.txt' (or whatever you want to call it). This file can then be opened in OpenBugs and used as input in a Bayesian model! Well, I hope this helps and facilitates your Bayesian analysis work!