Skip to content

Commit

Permalink
add [<-.sf that fixes agr attribute;
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Aug 16, 2023
1 parent e6de6c2 commit b301342
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ S3method("$",z_range)
S3method("$<-",sf)
S3method("[",sf)
S3method("[",sfc)
S3method("[<-",sf)
S3method("[<-",sfc)
S3method("[[<-",sf)
S3method("st_agr<-",sf)
Expand Down
10 changes: 9 additions & 1 deletion R/agr.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ st_agr.default = function(x = NA_character_, ...) {
#' @name st_agr
#' @export
st_set_agr = function(x, value) {
st_agr(x) = value
if (!missing(value))
st_agr(x) = value
else { # needs repair?
value = st_agr(x)
if (any(is.na(names(value))) && length(value) == length(x) - 1) {
names(value) = setdiff(names(x), attr(x, "sf_column"))
st_agr(x) = value
}
}
x
}

Expand Down
5 changes: 5 additions & 0 deletions R/sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ st_sf = function(..., agr = NA_agr_, row.names,
}
}

#' @export
"[<-.sf" = function(x, i, j, value) {
st_set_agr(NextMethod())
}

#' @export
"[[<-.sf" = function(x, i, value) {
agr = st_agr(x)
Expand Down

0 comments on commit b301342

Please sign in to comment.