From rlee at inverness.fpcc.net  Mon Jun 20 00:53:21 2005
From: rlee at inverness.fpcc.net (Lopaka Lee (Rob))
Date: Sun, 19 Jun 2005 16:53:21 -0600 (MDT)
Subject: [Rd] 1-based arrays and copying vectors
Message-ID: <32898.70.59.24.172.1119221601.squirrel@webmail.fpcc.net>

I'm interfacing to C code that uses 1-based indexing on arrays -- it
ignores the zeroth element.  Thus, input vectors from R must be moved up
one, and output arrays must be moved down one.

What is the best way to deal with this using R internal code?

My current approach is:

For an input R vector of length n, allocate a new vector(v) of length n+1
and copy input into v[1] to v[1+n].  Call with new vector.

For an output array(a) of length n, allocate a new vector of length n-1
and copy a[1] to a[n] into v[0] to v[n-1].

If this is the best approach, is there an idiom for copying vectors?

-Lopaka



[Rd] 1-based arrays and copying vectors
Lopaka Lee (Rob