Skip to content

Commit

Permalink
fix for #16
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Aug 20, 2018
1 parent a1a0dc0 commit 6aac414
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/sfencoded.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ str.wkt_column <- strSfEncoded

#' @export
`[.sfencoded` <- function(x, i, j, ..., drop = TRUE) {


encodedClass <- attr(x, 'class')[1]
geomColumn <- attr(x, "encoded_column")
wktColumn <- attr(x, "wkt_column")
attr(x, "sfAttributes") <- NULL
Expand All @@ -35,7 +36,11 @@ str.wkt_column <- strSfEncoded

if( is.null(attr(x, "encoded_column")) && is.null(attr(x, "wkt_column")) ){
x <- removeSfencodedClass(x)
} else {
## re-attach 'sfencoded' attribute?
attr(x, 'class') <- unique(c(encodedClass, attr(x, 'class')))
}

return(x)
}

Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-sfencoded.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ test_that("sfencoded converted to data.frame", {
expect_true(class(x) == "data.frame")
})

test_that("subsetting retains all class attributes", {

testthat::skip_on_cran()
library(sf)
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = T)
enc <- encode(nc)
expect_true(all(attr(enc, 'class') == attr(enc[1, ], 'class')))

})

test_that("sfencoded attributes are removed", {

testthat::skip_on_cran()
Expand Down

0 comments on commit 6aac414

Please sign in to comment.