<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: [ADMB Users] running admb from R using system()</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>It's much less elegant than Mark's code because directories and model names are hard wired but for multiple instances such as multiple mcmc chains, i've been successful using system() as shown below (64 bit windows, R version 2.11.0).<BR>
<BR>
setwd("dirname1")<BR>
system("model -commandoptions",wait=F,show.output.on.console=F,invisible=F)<BR>
<BR>
setwd("dirname2")<BR>
system("model -commandoptions",wait=F,show.output.on.console=F,invisible=F)<BR>
<BR>
<BR>
It's been a while since i set this up but remember having some issues with the show.output.on.console option using system().  The default for this option is show.output.on.console = TRUE.<BR>
<BR>
good luck.<BR>
<BR>
NG<BR>
<BR>
-----Original Message-----<BR>
From: users-bounces@admb-project.org on behalf of Mark Maunder<BR>
Sent: Mon 31/05/2010 9:08 AM<BR>
To: Benedikt Gehr; users@admb-project.org<BR>
Subject: Re: [ADMB Users] running admb from R using system()<BR>
<BR>
Try this<BR>
<BR>
   if (.Platform$OS.type == "windows") {<BR>
        shell(paste(exedr, file_name,<BR>
            ".exe", " ", cmdoptions, sep = ""), invisible = TRUE)<BR>
    }<BR>
    else {<BR>
        system(paste("cp ", exedr,<BR>
            file_name, " .", sep = ""))<BR>
        system(paste("./", file_name, " ", cmdoptions, sep = ""))<BR>
        unlink(file_name)<BR>
    }<BR>
<BR>
<BR>
<BR>
Mark Maunder<BR>
Head of the Stock Assessment Program<BR>
Inter-American  Tropical Tuna Commission<BR>
8604 La Jolla Shores Drive<BR>
La Jolla, CA, 92037-1508, USA<BR>
 <BR>
Tel: (858) 546-7027<BR>
Fax: (858) 546-7133<BR>
mmaunder@iattc.org<BR>
<A HREF="http://www.fisheriesstockassessment.com/TikiWiki/tiki-index.php?page=Mar">http://www.fisheriesstockassessment.com/TikiWiki/tiki-index.php?page=Mar</A><BR>
k+Maunder<BR>
<BR>
Visit the AD Model Builder project at<BR>
 <A HREF="http://admb-project.org/">http://admb-project.org/</A><BR>
<BR>
See the following website for information on fisheries stock assessment<BR>
<A HREF="http://www.fisheriesstockassessment.com/">http://www.fisheriesstockassessment.com/</A><BR>
<BR>
-----Original Message-----<BR>
From: users-bounces@admb-project.org<BR>
[<A HREF="mailto:users-bounces@admb-project.org">mailto:users-bounces@admb-project.org</A>] On Behalf Of Benedikt Gehr<BR>
Sent: Monday, May 31, 2010 1:44 AM<BR>
To: users@admb-project.org<BR>
Subject: [ADMB Users] running admb from R using system()<BR>
<BR>
Hi<BR>
<BR>
I'm trying to run an admb model from R by using the system () command.<BR>
The admb model runs fine when running it from the admb command line or<BR>
when using emacs. However when I try it with system() then R crashes<BR>
every time.<BR>
And I tried using the R command line and RGui and in both it crashes. I<BR>
also tried it from different computers.<BR>
<BR>
What I do is I first set the directory where I keep the admb template<BR>
file with the corresponding admb data file and then invoke the system<BR>
command either step by step or directly. I can build the model but when<BR>
executing the model.exe file R crashes.<BR>
<BR>
##########################<BR>
#setting the working directory<BR>
setwd("Documents and Settings\\Beni User\\Desktop\\Transfer\\Model<BR>
Fournier\\admb models\\simulated data\\stochastic\\pooled age classes")<BR>
<BR>
#building the model -> this works fine<BR>
system('makeadm stocpool')<BR>
<BR>
#running the model -> makes R crash<BR>
system('stoc.exe')<BR>
###########################<BR>
#or directly like this:<BR>
setwd("Documents and Settings\\Beni User\\Desktop\\Transfer\\Model<BR>
Fournier\\admb models\\simulated data\\stochastic\\pooled age classes")<BR>
system("./stocpool") -> makes R crash right away<BR>
<BR>
<BR>
Does anyone know why this happens and how I can make this work?<BR>
<BR>
Thanks a lot for the help!!<BR>
<BR>
cheers<BR>
<BR>
Beni<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
_______________________________________________<BR>
Users mailing list<BR>
Users@admb-project.org<BR>
<A HREF="http://lists.admb-project.org/mailman/listinfo/users">http://lists.admb-project.org/mailman/listinfo/users</A><BR>
_______________________________________________<BR>
Users mailing list<BR>
Users@admb-project.org<BR>
<A HREF="http://lists.admb-project.org/mailman/listinfo/users">http://lists.admb-project.org/mailman/listinfo/users</A><BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>