Skip to content

Commit

Permalink
updated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dusadrian committed Apr 3, 2024
1 parent a396a36 commit 77a659b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 40 deletions.
78 changes: 38 additions & 40 deletions R/vctrs.R
Original file line number Diff line number Diff line change
@@ -1,44 +1,7 @@
# Dynamically exported, see onLoad.R
# using eval (parse ()) to avoid the huge dependency tree of vctrs, haven,
# 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)
}
# using eval(parse()) to avoid the huge dependency tree of vctrs, haven,
# labelled and pillar; these functions will be registered when or if the
# package vctrs is loaded

`vec_ptype_abbr.declared` <- function (x, ...) {
command <- "vctrs::vec_ptype_abbr(vctrs::vec_data(unclass (undeclare (x))))"
Expand All @@ -65,3 +28,38 @@
# )
# eval (parse (text = command))
# }

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

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

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

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

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

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

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

attrs$na_index <- na_index
attributes(x) <- attrs
return (x)
}
6 changes: 6 additions & 0 deletions inst/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 0.25
o Fixed bug in undeclare() with numeric values and character (declared)
missing values (thanks to Kyle Husmann for the report)
o New methods for vec_proxy() and vec_restore() for objects of class
"declared" (thanks to Kyle Husmann for the PR)

Version 0.24
o Objects of class "Date" are now accepted as input for a declared object.
o The package no longer automatically coerces from numeric to integer.
Expand Down

0 comments on commit 77a659b

Please sign in to comment.