Bickel, David
2004-May-12 20:03 UTC
[R] non-interactive call to R (running an R package as a stand-alone application)
Is there a way I can have R automatically execute the commands in a source file without ever having to use R interactively? If so, what arguments should I pass to the UNIX call to R? I need to do this to run several R jobs in parallel. An alternative may be to have R and an R package behave as a stand-alone application that can be called from the UNIX command line. Is there any documentation on this? S-PLUS can do something like this. I will be using Red Hat Linux. Thank you, David ______________________________ David Bickel http://davidbickel.com Research Scientist Pioneer Hi-Bred International Bioinformatics & Discovery Research 7250 NW 62nd Ave., PO Box 552 Johnston, Iowa 50131-0552 706-736-9151 Home 515-334-4739 Work 515-334-6634 Fax david.bickel at pioneer.com, bickel at prueba.info This communication is for use by the intended recipient and ...{{dropped}}
Peter Dalgaard
2004-May-12 20:29 UTC
[R] non-interactive call to R (running an R package as a stand-alone application)
"Bickel, David" <DAVID.BICKEL at PIONEER.COM> writes:> Is there a way I can have R automatically execute the commands in a > source file without ever having to use R interactively? If so, what > arguments should I pass to the UNIX call to R? I need to do this to > run several R jobs in parallel.Yes; help(BATCH) tells you one of them. (Somewhat surprising, this is not in the FAQ. It is mentioned in the R-intro manual though, and comes out of R --help). -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
R-users, I am simulating a birth process for 4 classes of individuals with l[i] being the average No. fetuses per individual. However, I need to bound the resulting values for each generated rpois to be <=3 (no individual can have > 3 offspring). I have not been able to figure out how to incorporate this into the below example. Any suggestions on integrating would be appreciated. recruit.f <- c(12, 12, 25, 51) #No. females in each age class l <- c(.05, 1.22, 1.6, 1.8) #mean No. fetuses for each age class x <- sapply(lapply(1:4, function(i) rpois(recruit.f[i], l[i])), sum) TIA, Bret A. Collier Arkansas Cooperative Fish and Wildlife Research Unit University of Arkansas
Bret, the following should do: x <- sum(pmin(rpois(recruit.f, l),3)) Giovanni> Date: Wed, 12 May 2004 16:11:08 -0500 > From: Bret Collier <bacolli at uark.edu> > Sender: r-help-bounces at stat.math.ethz.ch > Precedence: list > > R-users, > I am simulating a birth process for 4 classes of individuals with > l[i] being the average No. fetuses per individual. However, I need to > bound the resulting values for each generated rpois to be <=3 (no > individual can have > 3 offspring). I have not been able to figure out how > to incorporate this into the below example. Any suggestions on integrating > would be appreciated. > > > recruit.f <- c(12, 12, 25, 51) #No. females in each age class > l <- c(.05, 1.22, 1.6, 1.8) #mean No. fetuses for each age class > x <- sapply(lapply(1:4, function(i) rpois(recruit.f[i], l[i])), sum) > > TIA, > > Bret A. Collier > Arkansas Cooperative Fish and Wildlife Research Unit > University of Arkansas > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________]
Bret, At a second thought, probably what you want is the following:> sum(apply(outer(0:3,l*recruit.f,dpois),2,function(x) sample(0:3,1,prob=x)))In this case the distribution of offsprings for each female is Poisson, conditional on # of offsprings <= 3. Giovanni> Date: Wed, 12 May 2004 16:31:49 -0500 (CDT) > From: Giovanni Petris <GPetris at uark.edu> > Sender: r-help-bounces at stat.math.ethz.ch > Cc: r-help at stat.math.ethz.ch > Precedence: list > > > Bret, > > the following should do: > > x <- sum(pmin(rpois(recruit.f, l),3)) > > Giovanni > > > Date: Wed, 12 May 2004 16:11:08 -0500 > > From: Bret Collier <bacolli at uark.edu> > > Sender: r-help-bounces at stat.math.ethz.ch > > Precedence: list > > > > R-users, > > I am simulating a birth process for 4 classes of individuals with > > l[i] being the average No. fetuses per individual. However, I need to > > bound the resulting values for each generated rpois to be <=3 (no > > individual can have > 3 offspring). I have not been able to figure out how > > to incorporate this into the below example. Any suggestions on integrating > > would be appreciated. > > > > > > recruit.f <- c(12, 12, 25, 51) #No. females in each age class > > l <- c(.05, 1.22, 1.6, 1.8) #mean No. fetuses for each age class > > x <- sapply(lapply(1:4, function(i) rpois(recruit.f[i], l[i])), sum) > > > > TIA, > > > > Bret A. Collier > > Arkansas Cooperative Fish and Wildlife Research Unit > > University of Arkansas > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > > > > -- > > __________________________________________________ > [ ] > [ Giovanni Petris GPetris at uark.edu ] > [ Department of Mathematical Sciences ] > [ University of Arkansas - Fayetteville, AR 72701 ] > [ Ph: (479) 575-6324, 575-8630 (fax) ] > [ http://definetti.uark.edu/~gpetris/ ] > [__________________________________________________] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________]