[Rd] GenGC changes

Kurt Hornik Kurt.Hornik@ci.tuwien.ac.at
Fri, 11 Aug 2000 07:54:32 +0200

>>>>> Kurt Hornik writes:

> As most R developers maybe are already aware of, R version 1.2.0
> introduced a new `generational' garbage collector which means that
> strings and vectors (and language objects) are handled differently
> from the numerical atomic types.

>> From ``Writing R Extensions'':

>        Earlier code was written in a style like.
>            VECTOR(dimnames)[0] = getAttrib(x, R_NamesSymbol);
>     but that is no longer allowed.  The functions `VECTOR_ELT' and
>     `SET_VECTOR_ELT' must now be used to access and set elements of a
>     generic vector.  There are analogous functions `STRING_ELT' and
>     `SET_STRING_ELT' for character vectors.
>        To convert existing code, use the following replacements.
>          original                 replacement
>          `foo = VECTOR(bar)[i]'   `foo = VECTOR_ELT(bar, i)'
>          `VECTOR(foo)[j] = bar'   `SET_VECTOR_ELT(foo, j, bar)'
>          `foo = STRING(bar)[i]'   `foo = STRING_ELT(bar, i)'
>          `STRING(foo)[j] = bar'   `SET_STRING_ELT(foo, j, bar)'

> The changes were committed to the r-devel true this Monday, and imply
> that add-on packages using the original coding style will no longer
> work with current versions of r-devel.  One possible solution for
> having packages with sources which work for compilation under both 1.1
> and 1.2 is to use conditionals of the form

>     #if R_VERSION >= R_Version(1, 2, 0)
> 	new-style-code
>     #else
> 	old-style-code
>     #endif

> I would like to ask add-on package maintainers of packages which are
> affected by the change to produce updated versions of their packages
> which work under both 1.1 and 1.2.  It seems that the following ones
> require action:

> 	Java
> 	Matrix
> 	foreign
> 	hdf5
> 	netCDF
> 	stataread

> (Note that [currently], there is binary incompatibility between 1.1
> and 1.2.)

As indicated, the above is only one possible solution.  Another, and
maybe the preferred one in order to avoid unnecessarily duplicating
code, is the use of a *PRIVATE* header file containing the following

#if R_VERSION < R_Version(1, 2, 0)
# define STRING_ELT(x,i)	(STRING(x)[i])
# define VECTOR_ELT(x,i)        (VECTOR(x)[i])
# define SET_STRING_ELT(x,i,v)	(STRING(x)[i] = (v))
# define SET_VECTOR_ELT(x,i,v)	(VECTOR(x)[i] = (v))

(Note that in order to achieve maximal source compatibility in the 1.x
series, it is preferable to have add-on packages modified, as we cannot
easily control the `old' (pre-1.1.1) R versions included in various

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