[R] Multiple expressions in system.time()?

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jul 25 08:43:06 CEST 2003


On Thu, 24 Jul 2003, Dirk Eddelbuettel wrote:

> On Thu, Jul 24, 2003 at 07:10:27PM -0700, Robert Keefe wrote:
> > # This I can do:
> > > system.time(x <- rnorm(100000))
> > [1] 0.07 0.00 0.13 0.00 0.00
> > 
> > # But this I can't:
> > > system.time(x <- rnorm(100000); new <- sample(x, 100000, replace=T))
> > Error: syntax error
> 
> Just use curly braces:

(which make a single expression out of many)

> 
> > system.time({x <- rnorm(100000); new <- sample(x, 100000, replace=T)})
> [1] 0.11 0.00 0.11 0.00 0.00
> 
> > Have I missed something simple?
> 
> See above. Another related way is to define a function; you could even use a
> 'throw-away anonymous' function [1].
> 
> Lastly, you probably also want to learn about profiling your code. There is
> an introductory article in one of the R News issues.

Later information is in a chapter of the `Writing R Extensions' manual.
(A few things have changed since that R-News article).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list