On 11/26/2010 08:42 AM, BXC (Bendix Carstensen) wrote:
> Take a look at the course material from a course given two years ago:
>
> http://staff.pubhealth.ku.dk/~bxc/Bayes/Cph-2008/
>
> Under the link "Solution R-code for practicals" you will find a number of example files where
> bugs code is embedded in an R-program, for example in the file sol6.R.
>
> The trick is to use the R-function cat() that writes verbatim to a file:
>
> cat( " <here is your Bugs program....> ", file="m1.bug" )
> bugs( data=..., etc, etc,
> model="m1.bug" )
>
> This way you do not have to poke around with two files; I assume that this was what you were after.
Before you go too far down this road, consider that mixed code breaks
syntax highlighting for some (many?) editors and can make both the R an
BUGS code a nightmare to debug. Both Kate and vim have issues with
mixed code types.
Also, given the similarity in syntax between the two languages it can be
hard to tell whether you are looking at R or BUGS code when you
(quickly) read the code yourself.
Personally, I started doing this and promptly stopped for the reasons
given above.
Krzysztof
-----------------------------------------------
Krzysztof Sakrejda-Leavitt
Organismic and Evolutionary Biology
University of Massachusetts, Amherst
319 Morrill Science Center South
611 N. Pleasant Street
Amherst, MA 01003
work #: 413-325-6555
email: [log in to unmask]
-----------------------------------------------
>
> For nicety you could insert in your R-code:
>> shell("del m1.bug")
> or:
>> shell("rm m1.bug")
>
> Best regards,
> Bendix
> _________________________________________
>
> Bendix Carstensen
> Senior Statistician
> Steno Diabetes Center A/S
> Niels Steensens Vej 2-4
> DK-2820 Gentofte
> Denmark
> +45 44 43 87 38 (direct)
> +45 30 75 87 38 (mobile)
> [log in to unmask] www.biostat.ku.dk/~bxc
> www.steno.dk
>
>
>
>> -----Original Message-----
>> From: (The BUGS software mailing list)
>> [mailto:[log in to unmask]] On Behalf Of Maas James Dr (MED)
>> Sent: 26. november 2010 23:51
>> To: [log in to unmask]
>> Subject: possible to embed winbugs model file within R file ?
>>
>> I'm using winbugs and/or jags with a couple of analyses and
>> in both cases the standard syntax is to ask the function to
>> call an "bugs" model file which is external. Can anyone tell
>> me if it is possible to have the R script file contain the
>> bugs model file as well, perhaps as a function, and if so how ?
>>
>>
>>
>> I realise this question might be more appropriate in R
>> listserv but thought would try this first.
>>
>>
>>
>> Thanks
>>
>>
>>
>> Jim
>>
>> ===============================
>>
>> Dr. Jim Maas
>>
>> University of East Anglia
>>
>>
>>
>> --------------------------------------------------------------
>> ----- This list is for discussion of modelling issues and the
>> BUGS software. For help with crashes and error messages,
>> first mail [log in to unmask] To mail the BUGS list, mail
>> to [log in to unmask] Before mailing, please check the
>> archive at www.jiscmail.ac.uk/lists/bugs.html Please do not
>> mail attachments to the list. To leave the BUGS list, send
>> LEAVE BUGS to [log in to unmask] If this fails, mail
>> [log in to unmask], NOT the whole list
>>
> -------------------------------------------------------------------
> This list is for discussion of modelling issues and the BUGS software.
> For help with crashes and error messages, first mail [log in to unmask]
> To mail the BUGS list, mail to [log in to unmask]
> Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
> Please do not mail attachments to the list.
> To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
> If this fails, mail [log in to unmask], NOT the whole list
>
--
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list
|