[Rd] hello World problem

Duncan Murdoch murdoch at stats.uwo.ca
Thu Jan 12 16:52:03 CET 2006


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



More information about the R-devel mailing list