From jean@stat.ubc.ca  Tue Feb  2 20:38:35 1999
From: jean@stat.ubc.ca (Jean Meloche)
Date: Tue, 02 Feb 1999 20:38:35 +0000
Subject: Suggestion
Message-ID: <36B7624B.80E92237@stat.ubc.ca>

I have to write extensions to R regularly.

One of them was an interface to a mysql database on a
different computer. The best way to do that is to have
something like

mysql<-function (dbname, host = "zap", user = "nobody", password = "ok") 
{
    handle <<- .RC("mysqlconnect", c(host, user, password, dbname))
}

and

query<-function (cmd) 
{
    .RC("mysqlquery", handle, cmd)
}

In other words, my mysql (written in C) functions return a true R object.
The .RC function above simply calls the C funtion, passing R objects as
arguments and returns the R object created within the C function.

I think that R should give the ability to write C functions that build
R objects. Eventually, it would be best to have an API to standardize
the process of building R object too...

I'd like to see .RC added to the standard R distribution. Right now, I'm
applying my patch every time I upgrade R. Here is my diff


diff -r R-0.63/src/main/dotcode.c R-0.63.orig/src/main/dotcode.c
264,286d263
< SEXP do_dotRCode(SEXP call, SEXP op, SEXP args, SEXP env)
< {
<       DL_FUNC fun;
<       char buf[128], *p, *q, *vmax;
<       SEXP retval;
<
<       vmax = vmaxget();
<       op = CAR(args);
<       if (!isString(op)) errorcall(call,"function name must be a string\n");
<
<       /* make up load symbol & look it up */
<       p = CHAR(STRING(op)[0]);
<       q = buf; while ((*q = *p) != '\0') { p++; q++; }
<
<       if (!(fun=R_FindSymbol(buf))) errorcall(call,
<               "C-R function not in load table\n");
<
<       retval=fun(args);
<
<       vmaxset(vmax);
<       return retval;
< }
<
969c946
<       }
---
>         }
diff -r R-0.63/src/main/names.c R-0.63.orig/src/main/names.c
497d496
< {".RC",         do_dotRCode,    0,      1,      -1,     PP_FOREIGN},
diff -r R-0.63/src/main/names.h R-0.63.orig/src/main/names.h
128d127
< SEXP do_dotRCode(SEXP, SEXP, SEXP, SEXP);


If it is of interest, I could also provide the module that implements
the mysql interface.

Many thanks.

-- 
Jean Meloche
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Suggestion
Jean Meloche