[R] R_NilValue blows up on Windows

Vele Samak v.samak at verizon.net
Fri Aug 23 04:26:49 CEST 2002

Ok, Here's the c code that's loaded into R as dll on windows:

#include <R.h>
#include <Rdefines.h>
SEXP test1(SEXP col);

SEXP test1(SEXP col) 
  SEXP col2;
  Rprintf("no value!\n");
  return col2;

Compiles ok with bcc32 into a dll, loads into R as part of a library, I
Run library(rkdb), then 
> .Call("test1", 2)
no value!

And puf! Rterm crashes. 

What's the point of this? I developed a library for connecting to a kdb
database from within R. Similar to RODBC, but faster and more
streamlined for access of real-time tick data. Everything works great,
compiles on Win2000, R 1.3.1 and R 1.5.1 with Borland's free C++ 5.5,
and runs into .dll. All functions work great except when there's no data
from the database I do 
  if (nrows <= 0) {
    Rprintf("No rows...");
    return R_NilValue;
And there lies the blow up of Rterm!!! Apparently R_NilValue can be
assigned to any SEXP object internally, but when it's returned, Rterm
doesn't know what to do with it. I tried another bypass: 
  if (nrows <= 0) {
    Rprintf("No rows...");
    return NIL;
This works in most but not all cases. Weird! 

Any suggestions, comments are highly appreciated. Thanks,

Vele Samak

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list