From tlumley@u.washington.edu  Tue May  7 16:55:31 2002
From: tlumley@u.washington.edu (Thomas Lumley)
Date: Tue, 7 May 2002 08:55:31 -0700 (PDT)
Subject: [Rd] names(unlist(...)) may construct corrupt strings (PR#1524)
In-Reply-To: <200205071115.NAA07246@pubhealth.ku.dk>
Message-ID: <Pine.A41.4.44.0205070848330.50664-100000@homer39.u.washington.edu>

On Tue, 7 May 2002 oehl_list@gmx.de wrote:

> names(unlist(...)) seems to be able to construct corrupt strings
> detected via: two identical strings behave different in paste
> observed in RW1.4.1 and RW1.5.0
> pure replication code after output
>
> Best
>
>
> Jens Oehlschlgel
>
>
> > l <- names(unlist(list(aa = list(bb = 1))))
> > l
> [1] "aa.bb"

This is the same problem with do_paste that showed up with read.dta. If
you look at the C level, LENGTH() is 6 for l and 5 for "aa.bb".

In general we have the problem that a string has two ways of defining its
length:  LENGTH() and strlen()

Most functions use just one of these, but paste() uses LENGTH() to set up
the buffer and then strcpy() to copy into it. The string l has LENGTH 6,
but strlen 5, and the result from paste() is a string with a null as its
sixth character, which thus appears to be a five-character string.

Given that this is the second appearance of the problem perhaps do_paste()
should be changed instead of (as well as?) unlist().

	-thomas


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] names(unlist(...)) may construct corrupt strings (PR#1524)
Thomas Lumley