Skip to content

Commit

Permalink
Merge pull request #10 from khusmann/vctrs_fix
Browse files Browse the repository at this point in the history
implement vctrs vec_proxy() and vec_restore()
  • Loading branch information
dusadrian authored Apr 1, 2024
2 parents 8ed7ea1 + 37bbf83 commit d87cb23
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/onLoad.R
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@

register_S3_method("vctrs", "vec_ptype_abbr", "declared")
register_S3_method("vctrs", "vec_ptype_full", "declared")
register_S3_method("vctrs", "vec_proxy", "declared")
register_S3_method("vctrs", "vec_restore", "declared")
# register_S3_method("vctrs", "vec_ptype2", "declared")

register_S3_method("vroom", "output_column", "declared")
Expand Down
37 changes: 37 additions & 0 deletions R/vctrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,43 @@
# labelled and pillar these functions will be registered when or if the package
# vctrs is loaded

`vec_proxy.declared` <- function (x, ...) {
return (undeclare(x, drop=TRUE))
}

`vec_restore.declared` <- function(x, to, ...) {
new_attrs <- attributes(to)

misvals <- all_missing_values (
x,
new_attrs$na_values,
new_attrs$na_range,
new_attrs$labels
)

na_index <- which(is.element(x, misvals))

if (length(na_index) > 0) {
declared_nas <- x[na_index]

if (new_attrs$date) {
declared_nas <- as.numeric (declared_nas)
}

x[na_index] <- NA
names(na_index) <- declared_nas
}
else {
na_index <- NULL
}

new_attrs$na_index <- na_index

attributes(x) <- new_attrs

return (x)
}

`vec_ptype_abbr.declared` <- function (x, ...) {
command <- "vctrs::vec_ptype_abbr(vctrs::vec_data(unclass (undeclare (x))))"
return (
Expand Down

0 comments on commit d87cb23

Please sign in to comment.