[Rd] Invisible names problem

Pan Domu konto7628845339 @end|ng |rom gm@||@com
Wed Jul 22 21:29:53 CEST 2020


I ran into strange behavior when removing names.

Two ways of removing names:

    i <- rep(1:4, length.out=20000)
    k <- c(a=1, b=2, c=3, d=4)

    x1 <- unname(k[i])
    x2 <- k[i]
    x2 <- unname(x2)

Are they identical?

    identical(x1,x2) # TRUE

but no

    identical(serialize(x1,NULL),serialize(x2,NULL)) # FALSE

But problem is with serialization type 3, cause:

    identical(serialize(x1,NULL,version = 2),serialize(x2,NULL,version =
2)) # TRUE

It seems that the second one keeps names somewhere invisibly.

Some function can lost them, e.g. head:

    identical(serialize(head(x1, 20001),NULL),serialize(head(x2,
20001),NULL)) # TRUE

But not saveRDS (so files are bigger), tibble family keeps them but base
data.frame seems to drop them.

>From my test invisible names are in following cases:

   x1 <- k[i] %>% unname()
   x3 <- k[i]; x3 <- unname(x3)
   x5 <- k[i]; x5 <- `names<-`(x5, NULL)
   x6 <- k[i]; x6 <- unname(x6)

but not in this one
   x2 <- unname(k[i])
   x4 <- k[i]; names(x4) <- NULL

What kind of magick is that?

It hits us when we upgrade from 3.5 (when serialization changed) and had
impact on parallelization (cause serialized objects were bigger).

	[[alternative HTML version deleted]]



More information about the R-devel mailing list