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

Issue with inline R Notebook YAML header processing involving !expr #7545

Closed
4 tasks done
connorp opened this issue Aug 7, 2020 · 10 comments
Closed
4 tasks done

Issue with inline R Notebook YAML header processing involving !expr #7545

connorp opened this issue Aug 7, 2020 · 10 comments

Comments

@connorp
Copy link

connorp commented Aug 7, 2020

System details

RStudio Edition : Desktop
RStudio Version : 1.3.1056
OS Version      : macOS 10.15.5
R Version       : 4.0.2

Steps to reproduce the problem

  1. (With R freshly restarted) Create a new R Notebook file via the RStudio File menu, with the following contents (the specific function passed via !expr is not important to the reprex. kable() is used only as one example):

    ---
    title: "R Notebook"
    output: 
      html_notebook:
        df_print: !expr knitr::kable
    ---
    
    ```{r}
    plot(cars)
    ```
  2. Save the file.

  3. Run the code block inline. Observe the warning messages in the console, in addition to the expected plot.

  4. Restart R and clear output.

  5. Run the code block inline again. This time, there is no warning message.

Describe the problem in detail

yaml.load() now throws a warning when a YAML header includes an R expression to be evaluated, indicated by !expr, unless the eval.expr = TRUE option is explicitly set (and this warning will eventually be changed to an error). The rmarkdown package sets this option and works fine in knitted R Markdown documents, but when code is run inline within an R Notebook in RStudio, the code executes as expected, but the warnings are also still reported:

Warning messages:
1: In yaml.load(string, error.label = error.label, ...) :
  Evaluating R expressions (!expr) will soon require explicit `eval.expr` option (see yaml.load help)
2: In yaml.load(string, error.label = error.label, ...) :
  Evaluating R expressions (!expr) will soon require explicit `eval.expr` option (see yaml.load help)
3: In yaml.load(string, error.label = error.label, ...) :
  Evaluating R expressions (!expr) will soon require explicit `eval.expr` option (see yaml.load help)

Describe the behavior you expected

The code should be run without any warnings issued, regardless of whether R has been restarted or outputs cleared. Further discussion in rstudio/rmarkdown#1093.

@ronblum
Copy link
Contributor

ronblum commented Aug 10, 2020

@connorp Thank you for raising the issue, which I can reproduce in RStudio Desktop 1.4.673 on MacOS 10.15.6. We'll review it as we continue development of RStudio.

@stale
Copy link

stale bot commented Feb 5, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

@stale stale bot added the stale Issues which have been closed automatically due to inactivitiy. label Feb 5, 2021
@jmcphers jmcphers added this to the Later milestone Feb 10, 2021
@stale stale bot removed the stale Issues which have been closed automatically due to inactivitiy. label Feb 10, 2021
@joshpk
Copy link

joshpk commented Feb 23, 2021

Adding that this is still an issue

@cderv
Copy link
Collaborator

cderv commented Feb 25, 2021

For reference, I believe this happens because there are still some R code in the IDE using yaml 📦 which use the default, leading to this warning being thrown

Examples

yaml::yaml.load_file(templateYaml)

data <- .rs.scalarListFromList(yaml::yaml.load(yaml, handlers = handlers))

As a workaround, setting options(yaml.eval.expr = TRUE) in .Rprofile for example should remove the warning for this in the IDE.

For reference as mentioned above, rmarkdown sets eval.expr to TRUE in rmarkdown:::yaml_load

@cderv
Copy link
Collaborator

cderv commented Feb 10, 2022

FWIW the YAML package will probably use eval.expr = FALSE by default in upcoming version (vubiostat/r-yaml@d236f9a)

The message should disappear then, but maybe this will change some things as the IDE does rely on the default version and only has a handler for !r and not !expr.

@kevinushey
Copy link
Contributor

Does df_print: knitr::kable work? Couldn't rmarkdown read and evaluate the YAML string itself here?

@kevinushey
Copy link
Contributor

We could also evaluate whether we could make use of our embedded copy of yaml-cpp here.

@cderv
Copy link
Collaborator

cderv commented Feb 11, 2022

Couldn't rmarkdown read and evaluate the YAML string itself here?

rmarkdown sets eval.expr = TRUE by default in its reading function: https://github.com/rstudio/rmarkdown/blob/4c31109dbd6efa6d7e0df1f84689764c6adc591a/R/util.R#L133

yaml_load <- function(...) yaml::yaml.load(..., eval.expr = TRUE)
yaml_load_file <- function(input, ...) yaml_load(read_utf8(input), ...)

However, it only use the default provided handler for !expr and do not define a handler for !r. knitr does though as it is there that params are handled.

@kevinushey
Copy link
Contributor

Bumping milestone as I suspect this is going to affect almost all rmarkdown users.

@romainfrancois
Copy link
Contributor

Verified on build 2022.06.0 + 220.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants