Hello, I'm a newbie on this list. I have a R code but its execution take a very long time. Is it possible to compile it (in C for example) to decrease the execution time ? -- ---------------- Alexandre DEPIRE INRETS / GARIG
Depire Alexandre wrote:> Hello, > I'm a newbie on this list. > I have a R code but its execution take a very long time. > Is it possible to compile it (in C for example) to decrease the execution > time ?a) R is not C. b) No, we don't have an R compiler (except - in development - a byte compiler written by Luke Tierney, but that won't save magnitudes). You might want either to optimize the code, given it not very well written, or reqrite parts of the code in C. See the "Writing R Extensions" manual. Uwe Ligges
R is basically an interpreted language. To my knowledge, the standard approach to improving speed starts by finding which steps take the most time. This can be done using "proc.time" and / or "system.time" (preceded by "gc" to clean things up so the timing is more stable). Once you've determined which loop or function call consumes the most time, you then need to decide what to do about it. R is vectorized, so if you use loops like in Fortran or C, you might be able to replace complicated pieces of code with one or only a very few commands. This list has considered many questions about speed, so once you know which steps are taking the most time, you can search the archives as described in the posting guide, "http://www.R-project.org/posting-guide.html". If that does not solve the problem, you can translate a function into a compiled language like C. See help.start() -> "Writing R Extensions" -> "System and foreign language interfaces". hope this helps. spencer graves Depire Alexandre wrote:>Hello, >I'm a newbie on this list. >I have a R code but its execution take a very long time. >Is it possible to compile it (in C for example) to decrease the execution >time ? > > >
For figuring out where in the code the bottleneck is, a better tool is probably the profiler. See: http://cran.r-project.org/doc/manuals/R-exts.html#Profiling%20R%20code HTH, Andy> From: Spencer Graves > > R is basically an interpreted language. To my knowledge, the > standard approach to improving speed starts by finding which > steps take > the most time. This can be done using "proc.time" and / or > "system.time" (preceded by "gc" to clean things up so the > timing is more > stable). > > Once you've determined which loop or function call consumes the > most time, you then need to decide what to do about it. R is > vectorized, so if you use loops like in Fortran or C, you > might be able > to replace complicated pieces of code with one or only a very few > commands. This list has considered many questions about > speed, so once > you know which steps are taking the most time, you can search the > archives as described in the posting guide, > "http://www.R-project.org/posting-guide.html". If that does > not solve > the problem, you can translate a function into a compiled > language like > C. See help.start() -> "Writing R Extensions" -> "System and foreign > language interfaces". > > hope this helps. > spencer graves > > Depire Alexandre wrote: > > >Hello, > >I'm a newbie on this list. > >I have a R code but its execution take a very long time. > >Is it possible to compile it (in C for example) to decrease > the execution > >time ? > > > > > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
There was a real compiler which was under development as a MS thesis at Rice U last year, but I'm not sure if it was finished or ever will be released. I actually saw it in action on a small example... best, -tony On Fri, 7 Jan 2005 16:12:56 +0100, Depire Alexandre <depire at inrets.fr> wrote:> Hello, > I'm a newbie on this list. > I have a R code but its execution take a very long time. > Is it possible to compile it (in C for example) to decrease the execution > time ? > > -- > ---------------- > Alexandre DEPIRE > INRETS / GARIG > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- best, -tony "Commit early,commit often, and commit in a repository from which we can easily roll-back your mistakes" (AJR, 4Jan05). A.J. Rossini blindglobe at gmail.com
> From: A.J. Rossini > > There was a real compiler which was under development as a MS thesis > at Rice U last year, but I'm not sure if it was finished or ever will > be released. I actually saw it in action on a small example... > > best, > -tonyYes: http://hipersoft.cs.rice.edu/rcc/ (I believe Luke had gotten involved to some degree.) However, I'd still suggest trying to optimize the R code before trying other more drastic measures... Andy> On Fri, 7 Jan 2005 16:12:56 +0100, Depire Alexandre > <depire at inrets.fr> wrote: > > Hello, > > I'm a newbie on this list. > > I have a R code but its execution take a very long time. > > Is it possible to compile it (in C for example) to decrease > the execution > > time ? > > > > -- > > ---------------- > > Alexandre DEPIRE > > INRETS / GARIG > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > > > > -- > best, > > -tony > > "Commit early,commit often, and commit in a repository from > which we can easily > roll-back your mistakes" (AJR, 4Jan05). > > A.J. Rossini > blindglobe at gmail.com > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
On Fri, 7 Jan 2005, Marc Schwartz wrote:> On Fri, 2005-01-07 at 16:00 -0800, Sameul M Mwalili wrote: >> Dear ALL, >> In order to install the Rice R to C compiler (RCC) you need to patch >> the R source code. However, the patch command at DOS prompt returns an >> error: patch is not recognized as internal or external command. How >> do you patch in DOS (or Windows)? >> >> Regards, >> >> Samuel. > > The GNU patch program is available as source code via: > > http://www.fsf.org/software/patch/patch.html > > I also located a Sourceforge project that has pre-built native Win32 > binaries, which requires msvcrt.dll: > > http://unxutils.sourceforge.net/ > > There may be other resources to reference.Most of us use Cygwin (http://www.cygwin.com/). Gnuwin32 is also a good source (a bigger and more active project than unxutils): http://gnuwin32.sourceforge.net/ and their latest announcement is patch. Warning: the RCC patches are R-version specific, and the last available appears to be 1.9.0. Warning2: Some Windows versions of patch require CRLF files, and the R sources are LF files when unpacked by tar. -- 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