From pd@|gd @end|ng |rom gm@||@com  Mon Nov  1 15:55:15 2021
From: pd@|gd @end|ng |rom gm@||@com (peter dalgaard)
Date: Mon, 1 Nov 2021 15:55:15 +0100
Subject: [Rd] Wrong number of names?
In-Reply-To: <3b0ce089-f83b-3f58-93b4-51922178f4c1@stats.uwo.ca>
References: <3b0ce089-f83b-3f58-93b4-51922178f4c1@stats.uwo.ca>
Message-ID: <D8FC0C8F-77F4-40D2-AD46-54DBA99E7749@gmail.com>



> On 1 Nov 2021, at 11:36 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> 
> The StackOverflow post https://stackoverflow.com/a/69767361/2554330 discusses a dataframe which has a named numeric column of length 1488 that has 744 names. I don't think this is ever legal, but am I wrong about that?
> 

It is certainly not easy to create such objects at the R level, e.g.:

> x <- 1:10 
> names(x) <- 1:10 
> length(names(x)) <- 5
> x
   1    2    3    4    5 <NA> <NA> <NA> <NA> <NA> 
   1    2    3    4    5    6    7    8    9   10 
> names(x)
 [1] "1" "2" "3" "4" "5" NA  NA  NA  NA  NA 

or even

> x <- 1:10 
> attributes(x)$foo <- 1:5
> x
 [1]  1  2  3  4  5  6  7  8  9 10
attr(,"foo")
[1] 1 2 3 4 5
> names(attributes(x)) <- "names"
> x
   1    2    3    4    5 <NA> <NA> <NA> <NA> <NA> 
   1    2    3    4    5    6    7    8    9   10 
> dput(x)
structure(1:10, .Names = c("1", "2", "3", "4", "5", NA, NA, NA, 
NA, NA))

of course, at the C level, everything is possible...




> The `dat.rds` file mentioned in the post is temporarily available online in case anyone else wants to examine it.
> 
> Assuming that the file contains a badly formed object, I wonder if readRDS() should do some sanity checks as it reads.
> 
> Duncan Murdoch
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Wrong number of names?
peter dalgaard