From byron.ellis at gmail.com  Tue Apr  3 06:23:54 2007
From: byron.ellis at gmail.com (Byron Ellis)
Date: Mon, 2 Apr 2007 21:23:54 -0700
Subject: [Rd] R callbacks
In-Reply-To: <eb555e660704021751i30f8854m9f83c81d966ef6a@mail.gmail.com>
References: <eb555e660704021751i30f8854m9f83c81d966ef6a@mail.gmail.com>
Message-ID: <7098abec0704022123hd0806eesdeb54432dc6090e9@mail.gmail.com>

Hi Deepayan,

IIRC Rf_initialize_R sets up the pointers so ptr_R_WriteConsole is
just being overwritten by the original. You want to do it between
initialization and the mainloop

On 4/2/07, Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:
> Hi,
>
> I'm trying to understand (mostly from the R-exts manual) how to use
> the callbacks declared in Rinterface.h. As a first attempt, I'm trying
> to redefine ptr_R_WriteConsole in a very trivial manner. Here's my
> code:
>
> ---------------
> $ cat altr.c
>
> int Rf_initialize_R(int ac, char **av);
>
> #define R_INTERFACE_PTRS 1
> #include <Rinterface.h>
>
> extern int R_running_as_main_program;
>
> static void my_R_WriteConsole(char *buf, int len)
> {
>     printf("R<< %s", buf);
> }
>
> int main(int ac, char **av)
> {
>     R_running_as_main_program = 1;
>     ptr_R_WriteConsole = my_R_WriteConsole;
>     Rf_initialize_R(ac, av);
>     Rf_mainloop();
>     return 0;
> }
> ---------------
>
> I compile and run this in bash with
>
>
> RPROG=R
>
> INC=`${RPROG} CMD config --cppflags`
> LDF=`${RPROG} CMD config --ldflags`
> export LD_LIBRARY_PATH=`${RPROG} RHOME`/lib
> gcc -o altr ${INC} ${LDF} altr.c
>
> ${RPROG} CMD ./altr
>
> However, my customized version seems not to be used. What am I missing?
>
> -Deepayan
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>


-- 
Byron Ellis (byron.ellis at gmail.com)
"Oook" -- The Librarian



[Rd] R callbacks
Byron Ellis