[Rd] Wrong number of names?

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Mon Nov 1 15:55:15 CET 2021



> On 1 Nov 2021, at 11:36 , Duncan Murdoch <murdoch.duncan using 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 using 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 using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-devel mailing list