New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colonnade issue #120

Closed
earowang opened this Issue Jul 10, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@earowang

earowang commented Jul 10, 2018

Hi,

I'm not sure it's a bug or not, colonnade doesn't respect the actual value. I'd expect p_df would return df.

library(nanotime)
x <- nanotime("1970-01-01T00:00:00.000000001+00:00") + 0:4
df <- data.frame(time = x)
df
#>                                  time
#> 1 1970-01-01T00:00:00.000000001+00:00
#> 2 1970-01-01T00:00:00.000000002+00:00
#> 3 1970-01-01T00:00:00.000000003+00:00
#> 4 1970-01-01T00:00:00.000000004+00:00
#> 5 1970-01-01T00:00:00.000000005+00:00
p_df <- pillar::colonnade(df)
p_df
#>   time          
#>   <S4: nanotime>
#> 1 1             
#> 2 2             
#> 3 3             
#> 4 4             
#> 5 5

Created on 2018-07-10 by the reprex
package
(v0.2.0).

@krlmlr

This comment has been minimized.

Member

krlmlr commented Jul 10, 2018

Thanks. To illustrate what's happening here:

library(nanotime)
x <- nanotime("1970-01-01T00:00:00.000000001+00:00") + 0:4
x
#> [1] "1970-01-01T00:00:00.000000001+00:00"
#> [2] "1970-01-01T00:00:00.000000002+00:00"
#> [3] "1970-01-01T00:00:00.000000003+00:00"
#> [4] "1970-01-01T00:00:00.000000004+00:00"
#> [5] "1970-01-01T00:00:00.000000005+00:00"
format(x)
#> [1] "1970-01-01T00:00:00.000000001+00:00"
#> [2] "1970-01-01T00:00:00.000000002+00:00"
#> [3] "1970-01-01T00:00:00.000000003+00:00"
#> [4] "1970-01-01T00:00:00.000000004+00:00"
#> [5] "1970-01-01T00:00:00.000000005+00:00"
as.numeric(x)
#> [1] 1 2 3 4 5
as.character(x)
#> [1] "1" "2" "3" "4" "5"

Created on 2018-07-10 by the reprex package (v0.2.0).

pillar is not calling format() but as.character() by default, because the nanotime class doesn't implement a pillar_shaft() method (apparently). I'm not sure if this is a wise choice, maybe we should call format() instead?

@earowang

This comment has been minimized.

earowang commented Jul 10, 2018

Most time, if a new class is defined, the author would define format() for it, but not necessarily define pillar_shaft(). If format() hasn't been defined for this new class, format.default() gives a reasonable result.

@krlmlr krlmlr closed this in bb47d37 Jul 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment