param converted from data frame to list

Hi folks,

I am switching some files from RMarkdown to Quarto, and ran into a problem with one of my params.

I have two params:

  • county is a character string that defines which county to generate the report for.
  • doc.hist is a data frame with three columns (Version, Date, and Amendments).

These params work fine in RMarkdown, and the county parameter works for my new Quarto doc.

I am generating the reports the quarto package in R, using something like this:

quarto_render(input = quarto_file, execute_params = list(county = county, doc.hist = doc.hist))

My problem is that doc.hist gets converted to a list in Quarto, where each column is an element in the list, and each entry in the column in an element in that list, and my dates have been converted to a numeric that I'm not sure how to convert back (e.g., 1609891200).

I can probably figure out how to re-create my data frame in my quarto doc, but is there a way I can read it in directly as data frame/tibble?

Thanks!

Try changing list( to c( ?

Thanks for the suggestion.

The execute_params argument is looking for a "A list of named parameters", so when I try with c() instead, I get an error that "render params not declared in the YAML".

Long shot. I’ll try to replicate.

1 Like

Thanks! I will work on a reprex too. I thought this might be a known issue or that I was just missing something obvious.

I am working on getting my R / RStudio updated in case that helps (I was using R version 4.0.2 and RStudio 2021.09.0 Build 351).

execute_params is supposed to override front matter in the YAML block and I'm pretty sure you can't put a data frame in there. For this script

library(quarto)
county <- "Washington County"
Version <- 1.0
Date <- "2022-12-19"
Amendments <- "None"
quarto_render(execute_params = list(county = county, 
                                    Version = Version,
                                    Date = Date,
                                    Amendments = Amendments))

using this .qmd

'---
title: "myproject"
params:
county: "county"
Version: 0
Date: "1970-01-01"
Amendments: "Fourteenth"
'---

'{r} params$county params$Version params$Date params$Amendments '
I could render this to the screenshot

Thanks! I might end up doing something like this.

I'm curious about why the data frame doesn't work for the Quarto doc though, because it works fine with the RMarkdown file. The documentation for the arguments execute_params (from quarto_render) and params (from rmarkdown::render) both say

"A list of named parameters that override custom params specified within the YAML front-matter"

YAML entries have to be strings. But the good news I just found out is that the {YAML} package can convert data frames.

The column.major option determines how a data frame is converted into YAML. By default, column.major is TRUE.

Quarto is not R native, but R Markdown is. This explain why you can pass a Data Frame, which is a R object using a R argument in a R function (rmarkdown::render()). However, quarto render at command line is not R , and doesn't know about dataframe. When you do quarto_render() the R function will write for you the CLI command to execute, including passing parameters. Quarto can read parameters in a YAML format, and this is what the R function will do with your parameters (Quarto – Parameters)

Data frame have no representation in YAML - but list does. this is why writing and reading list works.

You need to find workaround for you R only parameter value. Some ideas:

  • Use list indeed
  • Pass a string as parameters to a file (like a .rds file or other that support data.frame object), where you can store your data.frame, and then read it in your parameterized document. I believe this would add one step only between creating the data.frame, and passing it to render function.

Hope it helps understand.

1 Like

Oh I see! Yes this does help me understand - thank you!

I should be able to find a workaround without too much trouble.

1 Like

Thank you! I will look into the YAML package.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.