From vqnguyen at uci.edu  Thu Sep 24 18:47:26 2009
From: vqnguyen at uci.edu (Vinh Nguyen)
Date: Thu, 24 Sep 2009 09:47:26 -0700
Subject: [Rd] R + C + Lapack toy regression example
In-Reply-To: <40e66e0b0909240550g363efe4ajfa49e8bfb5a6c3ae@mail.gmail.com>
References: <13c5a0ae0909230039w28389d5ch72f63ce5065d0e1d@mail.gmail.com> 
	<40e66e0b0909240550g363efe4ajfa49e8bfb5a6c3ae@mail.gmail.com>
Message-ID: <13c5a0ae0909240947j9b30247j731e1486d45b86e@mail.gmail.com>

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



[Rd] R + C + Lapack toy regression example
Vinh Nguyen