-
Notifications
You must be signed in to change notification settings - Fork 25
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
quarto_render changes the class of vectors containing NA values #168
Comments
Same with
|
Indeed. Thanks for the report. We are using yaml R package for writing the R objects, and they do use those special values because YAML spec does not have something for NA What would you expect a NA value in R to be in YAML ? I don't think R We could either add a handler for converting to To be conservative, we could error when we detect any NA in the conversion, asking to check the Curious of your thought on this. |
I don't have enough knowlegde about YAML to answer your question about the NA's. I don't think you should return an error when any value in But the original object class and values should be preserved when called with With
returns: With params:class: numeric Created within qmd file:class: numeric And in
returns : With params:class: logical Created within qmd file:class: logical |
Let me reintroduce the context here.
This means that for quarto, the only way to pass parameters is to use YAML syntax. And YAML syntax does not know about R objects. Now, This is where the big difference here is with So for example you can't pass a dataframe, or any other R specific object directly to
If you were to use CLI with So that is why I am thinking of an error if unsupported values are passed to For more example, this has been discussed also at
I won't close this here though because we indeed need to do something (prevent rendering or do force coercion to NULL ?) to avoid this Maybe in the future we'll find a solution in Quarto to have an API for yaml params that handles computation language specifics |
Thanks for the explanation and the new epic :) I still don't understand why it's working with logical vectors. According to the link you sent in your first message, if I understand well, the vector Can't we do the same with numeric and character vectors ?
When I pass a dataframe or a tibble, I get also a df or tibble with Maybe I'm naive but can we also pass the class of vectors in order to convert them back later ? |
Oh that is interesting ! Thanks for pointing this out! This is an issue from trying to solve #124 with 5207b6c Lines 6 to 16 in ba8485a
The handler for logical doesn't not handle NA specifically, and so if it encounters NA logical, it will use It seems it does not cause issues for a
Can you share an example of this please ?
This is not as simple right now. Quarto is a tool to work with any computations engine, so anything done as a built-in feature must be working for R Python Julia and maybe other in the future. Hence also the EPIC as the parameter feature is not yet at that level. Here we are:
So str(jsonlite::parse_json('[true, "NA", false]', simplifyVector = TRUE))
#> logi [1:3] TRUE NA FALSE This is indeed R specific here. Python does not have NA equivalent I think. Take this .Qmd file ---
title: "test"
format: html
---
```{python}
#| tags: [parameters]
#| echo: true
test_vec = "test_vec"
```
```{python}
test_vec
```
If you render with your example, library(quarto)
quarto_render("index.qmd",
execute_params = list(
test_vec = c(TRUE, NA, FALSE)
)) I got into some details, but I hope this illustrate why this is not as simple. In R Markdown, So this explain the current limitation and why this require some more design (quarto-dev/quarto-cli#9197) if we want to support an API for parameter that could allow engine specific consideration. |
I was wrong, the dataframes and tibbles are converted to lists. |
By the way, the workaround you suggested here https://forum.posit.co/t/param-converted-from-data-frame-to-list/155556/8 with RDS files works very well ! |
Until it's resolved, maybe you can add a warning in |
Thanks for the feedback. I'll make it more apparent in the doc, and I'll probably throw an error for those specific R values that can't be translated. IMO, they shouldn't be used in |
quarto_render() changes NA of numeric vectors to character ".na.real"
Similar to #124
Content of "test.qmd"
Returns:
With params:
class: character
values: 1, .na.real, 2.5, -6.33, NA, NA
is.na: FALSE, FALSE, FALSE, FALSE, TRUE, TRUE
Created within qmd file:
class: numeric
values: 1, NA, 2.5, -6.33, NaN,
is.na: FALSE, TRUE, FALSE, FALSE, TRUE, FALSE
This behaviour occurs also to columns of dataframes and tibbles.
Windows 11
rstudio version: 2023.12.1+402
Quarto 1.5.26
[>] Checking versions of quarto binary dependencies...
Pandoc version 3.1.11: OK
Dart Sass version 1.70.0: OK
Deno version 1.41.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
Version: 1.5.26
Path: C:\Users\xxxxxx\AppData\Local\Programs\Quarto\bin
CodePage: 1252
[>] Checking tools....................OK
TinyTeX: (not installed)
Chromium: (not installed)
[>] Checking LaTeX....................OK
Tex: (not detected)
[>] Checking basic markdown render....OK
[>] Checking Python 3 installation....(None)
Unable to locate an installed version of Python 3.
Install Python 3 from https://www.python.org/downloads/
[>] Checking R installation...........OK
Version: 4.3.3
Path: C:/PROGRA
1/R/R-431.3LibPaths:
- C:/Users/xxxxxx/AppData/Local/R/win-library/4.3
- C:/Program Files/R/R-4.3.3/library
knitr: 1.45
rmarkdown: 2.26
[>] Checking Knitr engine render......OK
The text was updated successfully, but these errors were encountered: