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

Documentation: Mix of two Higher Order Functions #2656

Open
yurovska opened this issue Feb 4, 2025 · 3 comments
Open

Documentation: Mix of two Higher Order Functions #2656

yurovska opened this issue Feb 4, 2025 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@yurovska
Copy link

yurovska commented Feb 4, 2025

Please select a category the issue is focused on?

Function Documentation

Let us know where something needs a refresh or put your idea here!

It is not really clear from documentation whether it's kinda "legitimate" to use one Higher Order function inside of another.

I mean, is that OK to do something like this?

advs <- advs %>%
  restrict_derivation(
    derivation = call_derivation,
    args = params(
      derivation = derive_vars_crit_flag,
      variable_params = list(
        params(
          condition = PCHG <= -5,
          description = "Body weight reduction ≥5% from baseline",
          crit_nr = 1
        ),
        params(
          condition = PCHG <= -10,
          description = "Body weight reduction ≥10% from baseline",
          crit_nr = 2
        ),
        params(
          condition = PCHG <= -15,
          description = "Body weight reduction ≥15% from baseline",
          crit_nr = 3
        ),
        params(
          condition = PCHG <= -20,
          description = "Body weight reduction ≥20% from baseline",
          crit_nr = 4
        ),
        params(
          condition = PCHG <= -25,
          description = "Body weight reduction ≥25% from baseline",
          crit_nr = 5
        )
      ),
      values_yn = TRUE,
      create_numeric_flag = FALSE
    ),
    filter = PARAMCD == "WGHT" & ONTRTFL == "Y"
  )
@bundfussr
Copy link
Collaborator

Yes, using higher order functions is fine because they fulfill the requirements for the derivation argument (first argument must expect a dataset and the function must return a dataset).

We should update the documentation and change

The function must provide the `dataset` argument and all arguments specified in the `params()` objects passed to the `arg` argument.

to

The function must provide all arguments specified in the `params()` objects passed to the `args` argument.

because the dataset argument is no longer expected.

@yurovska , what else would you suggest to update.

@yurovska
Copy link
Author

yurovska commented Feb 4, 2025

@yurovska , what else would you suggest to update.

@bundfussr Thanks a lot for your reply!

I remember somewhere there is a note saying that {dplyr} functions like mutate() are not suitable for the derivation argument. I think it is worth also to mention explicitly that another Higher Order function is fine there, and add at least one example.

@bundfussr
Copy link
Collaborator

I remember somewhere there is a note saying that {dplyr} functions like mutate() are not suitable for the derivation argument.

The note was removed when we updated the checks such that the first argument doesn't need to be named dataset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Development

No branches or pull requests

2 participants