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

Please allow us to disable param defaults #762

Closed
DianaCesar opened this issue Aug 5, 2016 · 8 comments · Fixed by #1115
Closed

Please allow us to disable param defaults #762

DianaCesar opened this issue Aug 5, 2016 · 8 comments · Fixed by #1115
Labels
bug an unexpected problem or unintended behavior

Comments

@DianaCesar
Copy link

DianaCesar commented Aug 5, 2016

This is more of a request than an issue.

Currently, when a parameterized .Rmd is created, a default value must be coded for each param. For example, if I have the following param in the YAML...

other: 
      value: first
      choices: [first, second, third]
      input: select
      label: Other
      multiple: yes

...then I must specify a default option to go into the 'value' spot. If I leave this spot blank, it throws an error*. If I try knitting this doc with the above code, then backspacing this param widget so that no value is showing, it returns the first available value (from my choices) in the rendered doc.

It seems that RMarkdown requires a default value for every param in order to render. Is there a way I could create a parameter with no defaults (i.e., a param that passes through to the output as NULL)?

*There seems to be some NULL capability built into params in RMarkdown, but it is unpredictable (or I am using it incorrectly). For example, when I leave the 'value:' spot blank (or I make it NULL) and knit the doc with parameters, I can sometimes get an option to appear in the select widget that says "Unspecified (NULL)" and another option that says "Use a custom value." Selecting the first option does pass a NULL value through to the output. Selecting the second option resets the widget to display my original choices, but throws an error during the knit. It seems like the more coder-friendly alternative would be to simply allow RMarkdown to interpret these NULL values (or blank widgets) as such, without displaying the extra options.

Thank you,

Diana

@yihui yihui added the bug an unexpected problem or unintended behavior label Aug 7, 2016
@aronatkins
Copy link
Contributor

Here is the error that is obtained when a multi-select value is chosen and then unset before choosing to knit with custom values:

Error in knit_params_get(input_lines, params) : 
  render params not declared in YAML: other
Calls: <Anonymous> -> knit_params_get
Execution halted

This indicates that knit_params_ask is not returning all parameters under some conditions.

@aronatkins
Copy link
Contributor

R Markdown does not require parameters to have defaults. The following documents will report params$other having a NULL value when it is knit:

    ---
    title: rmarkdown 762
    params:
      other:
        value:
        choices: [first, second, third]
        input: select
        label: Other
        multiple: yes
    ---

    ```{r}
    params$other
    ```

You could also specify: value: !r NULL.

@yihui / @jjallaire - How do you feel about assuming a parameter without a value takes NULL?

@aronatkins
Copy link
Contributor

I am investigating the error caused by knit_params_ask; the NULL default is an open question.

aronatkins added a commit that referenced this issue Aug 8, 2016
UI values may revert to NULL if their value is cleared. Take a multi-input, for
example. When choices are removed, its value becomes NULL. This was missing
before, as we blindly ignored NULL UI values.

part of #762
@aronatkins
Copy link
Contributor

I think #768 will improve handling of NULL values, but there is still work remaining.

@aronatkins
Copy link
Contributor

@DianaCesar Unfortunately, support for NULL values either as defaults, as programmatic overrides, or as UI selections is not well supported. Some permutations involving NULL may work, but I cannot recommend using NULL values at this time.

We hope to improve NULL support in an upcoming release.

@DianaCesar
Copy link
Author

OK. Thanks for the update.

@trestletech
Copy link
Contributor

A start to a solution: #913

This, paired with a required flag might accomplish what you're after. Even with just #913 you could in your own code stop() the compilation if you found that one of the parameters looked empty (for some definition of "empty").

@github-actions
Copy link

github-actions bot commented Nov 3, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants