Last active
May 15, 2017 15:43
-
-
Save cpsievert/1b42e4b5fd24dceebdb0315d0f49f44a to your computer and use it in GitHub Desktop.
str(arrow()) seems broken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(grid) | |
(a <- arrow()) | |
#> $angle | |
#> [1] 30 | |
#> | |
#> $length | |
#> [1] 0.25inches | |
#> | |
#> $ends | |
#> [1] 2 | |
#> | |
#> $type | |
#> [1] 1 | |
#> | |
#> attr(,"class") | |
#> [1] "arrow" | |
names(a) | |
#> [1] "angle" "length" "ends" "type" | |
mode(a) | |
#> [1] "list" | |
a[[2]] | |
#> [1] 0.25inches | |
# not what I'd expect! | |
str(a) | |
#> List of 1 | |
#> $ angle : num 30 | |
#> - attr(*, "class")= chr "arrow" | |
str(unclass(a)) | |
#> List of 4 | |
#> $ angle : num 30 | |
#> $ length:Class 'unit' atomic [1:1] 0.25 | |
#> .. ..- attr(*, "valid.unit")= int 2 | |
#> .. ..- attr(*, "unit")= chr "inches" | |
#> $ ends : int 2 | |
#> $ type : int 1 | |
#' Proposal arrow method for str() | |
#' @export | |
str.arrow <- function(object, ...) { | |
o <- oldClass(object) | |
oldClass(object) <- setdiff(o, "arrow") | |
str(object) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment