Skip to content

Commit

Permalink
✨implement vector methods, closes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
pierucci committed Dec 4, 2016
1 parent 308b878 commit de497bc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Generated by roxygen2: do not edit by hand

S3method("[",gho)
S3method("[<-",gho)
S3method("[[",gho)
S3method("[[<-",gho)
S3method(c,gho)
S3method(print,gho)
export(display_attribute_values)
export(display_attributes)
Expand Down
34 changes: 34 additions & 0 deletions R/vector-mehods.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' @export
`[.gho` <- function(x, i, ...) {
if (! is.null(attr(x, "attrs"))) {
attrs <- attr(x, "attrs")[i, ]
} else {
attrs <- NULL
}

build_gho(
as.vector(x)[i],
labels = attr(x, "labels")[i],
attrs = attrs
)
}

#' @export
`[[.gho` <- function(x, i, ...) {
x[i]
}

#' @export
`[<-.gho` <- function(x, ..., value) {
stop("Cannot replace parts of a GHO object.")
}

#' @export
`[[<-.gho` <- function(x, ..., value) {
stop("Cannot replace parts of a GHO object.")
}

#' @export
c.gho <- function(..., recursive = FALSE) {
stop("Cannot combine GHO objects.")
}

0 comments on commit de497bc

Please sign in to comment.