-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
A new non-derived variable in the library can be created from a set of start variables that are in a database. Similarly, a new derived variable
can be created from a combination of start variable(s) and other derived variables.
However, the library does not allow the creation of new derived/non-derived variable that uses a new derived/non-derived variable. For example the following test case,
test_that("Test", {
data <- data.frame(
start_a = c(1)
)
variables <- data.frame(
variable = c("a", "b", "c", "d"),
label = c("", "", "", ""),
labelLong = c("", "", "", ""),
units = c("N/A", "N/A", "N/A", "N/A"),
variableType = c("Continuous", "Continuous", "Continuous", "Continuous"),
databaseStart = c("database_one", "database_one", "database_one", "database_one"),
variableStart = c("[start_a]", "DerivedVar::[a]", "DerivedVar::[b]", "[c]")
)
database_name <- "database_one"
variable_details <- data.frame(
variable = c("a", "b", "c", "d"),
typeEnd = c("cont", "cont", "cont", "cont"),
databaseStart = c("database_one", "database_one", "database_one", "database_one"),
variableStart = c("[start_a]", "DerivedVar::[a]", "DerivedVar::[b]", "[c]"),
typeStart = c("cont", "cont", "cont", "cont"),
recEnd = c("copy", "Func::b", "Func::c", "copy"),
numValidCategories = c("N/A", "N/A", "N/A", "N/A"),
recStart = c("else", "else", "else", "else"),
catLabel = c("", "", "", ""),
catLabelLong = c("", "", "", "")
)
.GlobalEnv$b <- function(a) {
return(a + 1)
}
.GlobalEnv$c <- function(b) {
return(b+1)
}
recoded_data <- rec_with_table(
data, variables, database_name, variable_details)
print(recoded_data)
})
prints
| a | b | c | |
|---|---|---|---|
| 1 | 1 | 2 | 2 |
when it should print,
| a | b | c | d | |
|---|---|---|---|---|
| 1 | 1 | 2 | 3 | 3 |
In summary, the library should support use cases beyond only one level deep of recoding.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels