[R] run R under linux

Zhen Pang nusbj at hotmail.com
Tue Oct 21 06:33:22 CEST 2003


Dear all,

Our department uses the linux system and we are not allowed to submit job 
directly. We must make a batch to submit through "qmon".

so, I make a foo.sh file, which only contains one line: nohup R --vanilla < 
foo.txt > foo.results

foo is all my codes. It is a simulation of 200 times. I set the seed at the 
beginning. It is to estimate the success probability, which is very small, 
so my samples may be all 0s. I have tried, if the samples are all 0s, one 
parameter tends to be infinity, and one NA comes.

I want to do 200 simulations. I found during the fisrt 128 simulations, some 
parameters may be NAs, since I use if (abs(aold-anew)<1e-5) {print (anew)  
break} to break the one estimation. Some anew is not printed. I think NA 
comes. But for the 129th simulation, one matrix is singular and my program 
ends.

I want to know how to resume my program with the seeds saved, and do like 
continueing the 130th one without break. If possible, the results of the 
first 128 simulations can be saved and combine with the remaining 
simulation.

One more question is: in my code, I write the estimation of 200 simulations 
as a matrix aaa to a txt file. After the if (abs(aold-anew)<1e-5) {print 
(anew)  break}, I assign aaa[i]<- anew (where i is the number of 
simulation).  But I found although some anew is not printed, which I assume 
NA comes, the resulting matrix does not have NAs, they all be numbers. Why?


Regards,

Zhen


>From: michaell taylor <mt at michaelltaylor.com>
>To: R-help at stat.math.ethz.ch
>CC: nusbj at hotmail.com
>Subject: Re: [R] run R under unix
>Date: 09 Oct 2003 08:00:15 -0400
>
>One can run R 'txt', script files thusly:
>
>1. create the txt file (foo.txt) script.
>2. at a command prompt type :
>	R --vanilla < foo.txt > foo.results
>
>The file 'foo.results' will now have all the output that you normally
>would see on the screen.  This is actually quite useful in that you can
>move around freely within foo.results (using some sort of text editor) -
>unlike results written to a screen.
>
>This will only run while you are logged into the machine, however.  The
>best way to run a script without having to be logged in is through a
>batch processor. Indeed, for jobs running for days - your system
>administrator will be thrilled that it runs on the batch processor
>instead of interactively.  The method for doing this depends on your
>particular unix machine configuration, but a common method flow like
>this:
>
>1. Place the line:
>
>R --vanilla < foo.txt > foo.results
>
>into a file named foo.batch.  No other text should be in the file. Make
>this file executable via
>
> > chmod 755 foo.batch
>
>Then at the command line:
>
> > at -f foo.batch now
>
>or perhaps,
> > batch -f foo.batch
>
>If this does not work, ask your system administrator how to set up a
>batch process.
>
>The advantage of the batch process is 1) you need not be logged in, 2)
>your job will take a lower priority than interactive jobs.
>
>Michaell
>
>On Thu, 2003-10-09 at 01:52, Jason Turner wrote:
> > Zhen Pang wrote:
> > ...
> > > I now want to run the code under unix. However, I do not know how to 
>run
> > > this code in txt file under unix. I just log in to the unix and enter
> > > the R, what should I do next?
> > >
> > > One more question is: if I log off my computer when R is running under
> > > unix (i.e., disconnect my computer from server), will I get the result
> > > when I log in my computer next time?
> > ...
> >
> > You'll lose it if you run R in the normal, interactive way.  Running it
> > in the background will allow you to log out and still have it running, 
>but!
> >
> > 1) If you're not the only person using this machine, you learn the
> > command "nice" before you begin.
> > 2) I'm not certain you'll be able to produce jpeg or png graphics when
> > backgrounded; your backgrounded task needs access to the windowing
> > system for graphics rendering, and local security policy might prohibit
> > this.
> > 3) Save early, save often.  You probably already know that, but it bears
> > repeating.
> >
> > Here are some suggested steps to run your simulation in background mode.
> >   Unfortunately, the exact commands will depend on which version of Unix
> > you're using, and what command shells are available.  Consult your local
> > expert.
> >
> > 1) transfer the text file of commands to the unix machine.  FTP, using
> > ASCII mode is safest.
> > 2) log onto the Unix machine.
> > 3) run sh, ksh, or bash.  (the syntax for what follows is different for
> > the C shell, and I don't know it).
> > 4) using a stripped-down version of your script which will complete in a
> > short time (say, a minute or two), just to check that things work, type
> >
> > nohup nice 15 R < my.small.script >my.output 2>&1 &
> >
> > (again, learn what "nice" means before you use it.  This may not be
> > suitable, and it's impossible for me to tell from here if it is).
> >
> > I know that's not the full answer, but only someone who knows the local
> > setup can give you that answer.
> >
> > Cheers
> >
> > Jason
> > --
> > Indigo Industrial Controls Ltd.
> > http://www.indigoindustrial.co.nz
> > 64-21-343-545
> > jasont at indigoindustrial.co.nz
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help

_________________________________________________________________
Find love on MSN Personals http://personals.msn.com.sg/




More information about the R-help mailing list