From murdoch at stats.uwo.ca  Thu Jan 12 16:52:03 2006
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Thu, 12 Jan 2006 10:52:03 -0500
Subject: [Rd] hello World problem
In-Reply-To: <43C679C6.7050709@free.fr>
References: <43C679C6.7050709@free.fr>
Message-ID: <43C67B23.3000705@stats.uwo.ca>

On 1/12/2006 10:46 AM, Romain Francois wrote:
> Hi,
> 
> I'm trying to build a simple R package 'helloWorld' with just one 
> function that prints 'hello World' on the C side.
> I agree that it is completely useless, but I just start mixing R and C.
> 
> My C file is as follows :
> 
> #include <stdio.h>
> void helloWorld() {
>   printf("hello world !\n") ;
> }
> 
> When I call it from R, here is what happens :
> R> .C("helloWorld", PACKAGE = "helloWorld")
> hello world !
> list()
> 
> is it normal that 'list()' is printed ?

Yes, because that is the return value from .C.  If you don't want to 
print it, you could call

invisible(.C( ... ))

or, more likely, you'd embed this call in a function that produced its 
own return value after calling .C().

By the way, you should call Rprintf() rather than printf(), if you want 
your function to work in environments like Windows Rgui.  See the 
Writing R Extensions manual for the details.

Duncan Murdoch



[Rd] hello World problem
Duncan Murdoch