Skip to content

Commit 7e47070

Browse files
committed
[188532827]: deprecate setting derivation after variable is created
1 parent a724b53 commit 7e47070

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

R/variable-derivation.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ setMethod("derivation<-", c("CrunchVariable", "ANY"), function(x, value) {
123123
# silently takes and discards `value` to make method dispatch easier
124124
integrateDerivedVar <- function(x, value) {
125125
if (is.derived(x)) {
126+
warn_once(paste0(
127+
"Materializing an existing derived variable is deprecated and will not work in the future. ",
128+
"Prefer setting `derived=FALSE` when creating a variable over changing it later."
129+
), option = "warnIntegrateDerivedVar")
130+
126131
payload <- toJSON(list(derived = FALSE))
127132
crPATCH(self(x), body = payload)
128133

tests/testthat/test-derive.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ with_mock_crunch({
4848
})
4949

5050
test_that("derivation()<-NULL and is.derived()<-FALSE issues a PATCH", {
51-
expect_PATCH(
52-
derivation(birthyrPlus) <- NULL,
53-
"https://app.crunch.io/api/datasets/1/variables/birthyrPlus/",
54-
'{"derived":false}'
51+
set_crunch_opts("warnIntegrateDerivedVar" = FALSE)
52+
expect_warning(
53+
expect_PATCH(
54+
derivation(birthyrPlus) <- NULL,
55+
"https://app.crunch.io/api/datasets/1/variables/birthyrPlus/",
56+
'{"derived":false}'
57+
),
58+
"Materializing an existing derived variable is deprecated"
5559
)
5660
expect_PATCH(
5761
is.derived(birthyrPlus) <- FALSE,

0 commit comments

Comments
 (0)