I have created a class called time
. This is a dummy example which return seconds as minute. This works well, But the print.time
function is not used inside a tbl.
Any ide how I can adapt the display inside a tbl ?
Regards
see reprex here
library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
as.time <- function(x){
class(x)<-"time"
x
}
print.time<-function(x,...){
print.default(unclass(x/60))
invisible(x)
}
60 %>% as.time() %>% print()
#> [1] 1
tribble(~a,~time,
"a",123,
"b",234,
"c",456
) %>% mutate(time = as.time(time))
#> # A tibble: 3 x 2
#> a time
#> <chr> <dbl>
#> 1 a 123
#> 2 b 234
#> 3 c 456
Created on 2019-02-07 by the reprex package (v0.2.1)