Skip to content

Commit

Permalink
fix redist revdep problem; #1958
Browse files Browse the repository at this point in the history
* redist problem see alarm-redist/redist#148
  • Loading branch information
edzer committed Jul 8, 2022
1 parent 45016c5 commit 2df4b5c
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions R/tidyverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,42 @@
#' @name tidyverse
dplyr_col_modify.sf <- function(data, cols){
x <- NextMethod()
dplyr::dplyr_reconstruct(x, data)
dplyr_reconstruct.sf(x, data)
}

#' @name tidyverse
dplyr_row_slice.sf <- function(data, i, ...){
x <- NextMethod()
dplyr::dplyr_reconstruct(x, data)
dplyr_reconstruct.sf(x, data)
}

# This is currently only used in `bind_rows()` and `bind_cols()`
# because sf overrides all default implementations
#' @name tidyverse
dplyr_reconstruct.sf = function(data, template) {
sfc_name = attr(template, "sf_column")
if (inherits(template, "tbl_df"))
data = dplyr::as_tibble(data)
class(data) = setdiff(class(template), "sf")

# Return a bare data frame is the geometry column is no longer there
# Return a bare data frame is the geometry column is no longer there or invalid:
if (!sfc_name %in% names(data) || !inherits(data[[sfc_name]], "sfc"))
return(data)

prec = st_precision(template)
crs = st_crs(template)

st_as_sf(
data,
sf_column_name = sfc_name,
crs = crs,
precision = prec
)
data
else {
prec = st_precision(template)
crs = st_crs(template)
agr = if (!is.null(agr <- attr(data, "agr")) && is.factor(agr)) {
att = names(data)[!sapply(data, inherits, what = "sfc")] # non-sfc columns
setNames(agr[att], att) # NA's new columns
} else
NA_agr_

st_as_sf(
data,
sf_column_name = sfc_name,
crs = crs,
precision = prec,
agr = agr
)
}
}

group_split.sf <- function(.tbl, ..., .keep = TRUE) {
Expand Down

0 comments on commit 2df4b5c

Please sign in to comment.