Skip to content

Commit

Permalink
Use NextMethod in Extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
nutterb committed Jul 27, 2018
1 parent 3c4b7bc commit 9a4eb66
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions R/extract_labelled.R
Expand Up @@ -22,7 +22,7 @@

`[.labelled` <- function(x, i, ...){
structure(
unclass(x)[i],
NextMethod(),
label = attr(x, "label"),
class = class(x)
)
Expand All @@ -32,11 +32,12 @@
#' @export

`[<-.labelled` <- function(x, i, value, ...){
x_new <- x
class(x_new) <- class(x_new)[!class(x_new) %in% "labelled"]
x_new[i] <- value
# x_new <- x
# class(x_new) <- class(x_new)[!class(x_new) %in% "labelled"]
# x_new[i] <- value
structure(
x_new,
# x_new,
NextMethod(),
label = attr(x, "label"),
class = c("labelled", class(x_new))
)
Expand Down

0 comments on commit 9a4eb66

Please sign in to comment.