Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Last active May 15, 2017 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpsievert/1b42e4b5fd24dceebdb0315d0f49f44a to your computer and use it in GitHub Desktop.
Save cpsievert/1b42e4b5fd24dceebdb0315d0f49f44a to your computer and use it in GitHub Desktop.
str(arrow()) seems broken
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