[Rd] R + C + Lapack toy regression example

Vinh Nguyen vqnguyen at uci.edu
Thu Sep 24 18:47:26 CEST 2009


thank you William Dunlap and professor Bates for your responses.
Since the first argument is always an "N" for linear regression, i
just placed
const char* trans = "N";
in my .c file and things worked.
See some comments below.

On Thu, Sep 24, 2009 at 5:50 AM, Douglas Bates <bates at stat.wisc.edu> wrote:
> In your C code you are treating that object as a C character string
> (char*) but that is not what is being passed.  Look at section 5.2 of
> "Writing R Extensions" - a character variable in R is passed by .C as
> a char**, not a char*.
>

so i suppose you can't get char* from R?  i tried as.raw and that
didn't work either.

> I find it much easier to use the .Call interface instead of the .C
> interface for applications like this.  You do need to learn some of
> the mysteries of the functions declared in Rinternals.h but, once you
> do, it is much easier to pass a matrix from R with and extract all the
> fussy details within the C code.  Several of the C source code files
> in the Matrix package are devoted to exactly the kind of operation you
> want to carry out.  Look at the function lsq_dense_QR in
> Matrix/src/dense.c, for example. (Although now that I look at it
> myself I see some questionable programming practices - I should have
> PROTECTed the result of coerceVector but it happens that it would not
> have needed protection.  Rather than coercing I should just check
> isInteger on the dim attribute.)

So if someone were to re-implement linear regression using C/C++ and
not fortran, would u imagine it being implemented via the .C()
function and using Lapack?  Or how would the matrix manipulations be
handled in C?

Thanks.
Vinh



More information about the R-devel mailing list