Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Does value_choices support delayed_data? #233

Closed
3 tasks done
chlebowa opened this issue Dec 24, 2024 · 0 comments · Fixed by #237
Closed
3 tasks done

[Question]: Does value_choices support delayed_data? #233

chlebowa opened this issue Dec 24, 2024 · 0 comments · Fixed by #237
Labels
core question Further information is requested

Comments

@chlebowa
Copy link
Contributor

What is your question?

value_choices seems to support the concept of delayed_data:
image
However, var_choices must be a character vector, delayed_data objects are not accepted.

Is this an oversight or am I missing something?

Also, the subset argument can accept a function that only takes a data argument, in keeping with other similar cases throughout the package, but this seems insufficient. In the example given in the documentation:

# functional subset
value_choices(ADRS, "PARAMCD", "PARAM", subset = function(data) {
  levels(data$PARAMCD)[1:2]
})

One must specify the variable manually and, again, delayed data does not seem to be supported.
Wouldn't something like this be more thorough?

value_choices(ADRS, "PARAMCD", "PARAM", subset = function(data, variable) {
  levels(data[[variable]])[1:2]
})

This way one could do

value_choices(
  data = "ADRS", 
  var_choices = variable_choices("ADRS", subset = function(data) names(Filter(is.factor, data))), 
  subset = function(data, variable) levels(data[[variable]])[1:2]
)

Or the function passed to subset could operate on a variable rather than the whole dataset.

Finally, passing choices_labeled to var_choices may run into another issue: [.tbl_df has very strict argument checks, which results in

> data <- cdisc_data(ADSL = rADSL)
> value_choices(
+   data[["ADSL"]],
+   var_choices = variable_choices(data[["ADSL"]], function(data) names(Filter(is.factor, data)))
+ ) |> summary()
Error in `data[var_choices]`:
! Can't subset columns with `var_choices`.
✖ `var_choices` must be logical, numeric, or character, not a <choices_labeled/character> object.
Run `rlang::last_trace()` to see where the error occurred.

but convert the tibble to a data.frame and

> data <- cdisc_data(ADSL = rADSL) |> within(ADSL <- as.data.frame(ADSL))
> value_choices(
+   data[["ADSL"]],
+   var_choices = variable_choices(data[["ADSL"]], function(data) names(Filter(is.factor, data)))
+ ) |> summary()
         Length          Class1          Class2            Mode 
            400 choices_labeled       character       character 

It seems value_choices.data.frame should rather do data[as.vector(var_choices)].

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
@chlebowa chlebowa added the question Further information is requested label Dec 24, 2024
@donyunardi donyunardi added the core label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants