Skip to content

Commit

Permalink
restore rownames for regular data.frames
Browse files Browse the repository at this point in the history
  • Loading branch information
ateucher committed Nov 28, 2024
1 parent a6f8fe8 commit db02c19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions R/utm-convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ format_zone <- function(x) {
restore_tibble <- function(new, original) {
if (inherits(original, c("tbl_df", "tbl"))) {
class(new) <- c(setdiff(class(new), class(original)), class(original))
} else {
rownames(new) <- rownames(original)
}
new
}
10 changes: 7 additions & 3 deletions tests/testthat/test-utm-convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,19 @@ test_that("Output minus sf stuff is same as input (#146)", {
sf::st_drop_geometry(out_tbl)[, setdiff(names(out_tbl), c("X", "Y", "geometry")), drop = FALSE]
)

# Check with bare data frame with row names
data_df <- as.data.frame(data)
rownames(data_df) <- letters[seq_len(nrow(data_df))]

out_df <- utm_convert(
as.data.frame(data),
data_df,
easting = "UTMe",
northing = "UTMn",
zone = "Zone"
)

expect_equal(
as.data.frame(data),
data_df,
sf::st_drop_geometry(out_df)[, setdiff(names(out_df), c("X", "Y", "geometry")), drop = FALSE]
)

Expand Down

0 comments on commit db02c19

Please sign in to comment.