hadley / adv-r

Advanced R: a book
http://adv-r.hadley.nz
Other
2.36k stars 1.71k forks source link

Incorrect result in `length(unclass(x))` #1768

Open Layalchristine24 opened 1 year ago

Layalchristine24 commented 1 year ago

In the section 13.5 Object styles, the result of length(unclass(x)) is 9, but it should be 11 as mentioned in the text. It might need to be knitted again.

x <- as.POSIXlt(ISOdatetime(2020, 1, 1, 0, 0, 1:3))
x
#> [1] "2020-01-01 00:00:01 CET" "2020-01-01 00:00:02 CET"
#> [3] "2020-01-01 00:00:03 CET"

length(x)
#> [1] 3
length(unclass(x))
#> [1] 11

x[[1]] # the first date time
#> [1] "2020-01-01 00:00:01 CET"
unclass(x)[[1]] # the first component, the number of seconds
#> [1] 1 2 3

instead of

x <- as.POSIXlt(ISOdatetime(2020, 1, 1, 0, 0, 1:3))
x
#> [1] "2020-01-01 00:00:01 CET" "2020-01-01 00:00:02 CET"
#> [3] "2020-01-01 00:00:03 CET"

length(x)
#> [1] 3
length(unclass(x))
#> [1] 9

x[[1]] # the first date time
#> [1] "2020-01-01 00:00:01 CET"
unclass(x)[[1]] # the first component, the number of seconds
#> [1] 1 2 3

I assign the copyright of this contribution to Hadley Wickham.