[Rd] debug R objects at C level

From: Adrian Duşa <dusa.adrian_at_gmail.com>
Date: Thu, 21 Jun 2012 14:38:29 +0300

Dear R-devel,

I am now at a debugging phase, and would like to inspect the (individual) values in an arbitrary R vector. It should be simple, but after hours of reading I am simply unable to find the right information.

A possible C code is:
# include <R.h>
# include <Rinternals.h>
# include <R_ext/Rdynload.h>

SEXP foo(SEXP x) // where x is a vector passed by an R function

    double *px;
    int i;
    px = REAL(x);

    for (i = 0; i < length(x); i++) {

        printf("%d\n", px[i]); // not good     }

That doesn't do the trick, because it only prints the pointer itself. What I'd like to do is to inspect is the actual vector value in the position i, that the pointer px[i] points to.

I read about PrintVector() in Rinternals.h, but that prints the whole R vector, while for debugging purposes I need to inspect individual values, one at at time.

Thanks in advance,

Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Tel.:+40 21 3126618 \
       +40 21 3120210 / int.101
Fax: +40 21 3158391

R-devel_at_r-project.org mailing list
Received on Thu 21 Jun 2012 - 11:41:30 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Jun 2012 - 12:10:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive