Re: [Rd] R_alloc problems in R v1.11

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Wed 06 Jul 2005 - 21:04:25 GMT

On Wed, 6 Jul 2005, [iso-8859-1] Marie-Hélène Ouellette wrote:

> Dear Dr. Ripley,

Or possibly other people on the list.

> I'm using the R v1.11 on Macintoch

Unlikely. There is no R v1.11, and R 1.1.1 (following the most common misspelling) wasn't available for the Mac.

> and I seem to have a problem with the
> function R_alloc. It crashes when using the following .C function (only an
> example):
>
> ///////////////////////////////
> # include <R.h>
> void Hello(int *n)
> {
> int i,x;
> for(i=1;1< *n ; i++)

This is an infinite loop. You probably mean i<*n as the second expression, or perhaps i<=*n (did you want n or n-1 repeats?)

> {
> Rprintf('salut!!!\n');

This is invalid C, as your compiler should have told you. You need double quotes.

> }
> x = (int *) R_alloc(5,sizeof(int));

x was declared as int, not int *, so again this is invalid.

> }
>
> ///////////////////////////////
>
> I call it in R with this line:
>
> .C('Hello',as.integer(5))
>
> Any idea why and how I can resolve this problem?

After fixing the C errors and in a version of R that exists (2.0.1) I get
> dyn.load("hello.so")
> .C('Hello',as.integer(5))

salut!!!
salut!!!
salut!!!
salut!!!

[[1]]
[1] 5

         -thomas



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Jul 07 07:06:57 2005

This archive was generated by hypermail 2.1.8 : Mon 24 Oct 2005 - 22:27:26 GMT