Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Sharing R environment between book chapters #1590

Open
andyofsmeg opened this issue Jul 29, 2022 · 9 comments
Open

Sharing R environment between book chapters #1590

andyofsmeg opened this issue Jul 29, 2022 · 9 comments
Labels
computations enhancement New feature or request
Milestone

Comments

@andyofsmeg
Copy link

I'm playing with Quarto Books for the first time having been a R/bookdown user for a while. I have a simple book with two chapters. In the first chapter I define a variable , x, and I want to then use x in my second chapter. In bookdown this works fine. But with Quarto I get, "Error in eval(expr, envir, enclos) : object 'x' not found" when I click render in RStudio. I'm very willing to accept user error, or that independence of chapters is a design choice. But it wasn't something I was expecting.

I've attached a worked example.

What I'm actually more interesting in working out is how to pass params (from a YAML header) from chapter to chapter. Previously I could include something like this in the index file:

---
params:
  hello: world
---

and then access it in all other chapters
test_params_quorto.zip
.

@cderv cderv transferred this issue from quarto-dev/quarto-r Jul 30, 2022
@cderv
Copy link
Collaborator

cderv commented Jul 30, 2022

bookdown defaults to a Merge and Knit approach where all the document are merged before knitting. Other approach Knit and Merge when new_session: true renders each file its own session. More on that in https://bookdown.org/yihui/bookdown/new-session.html

Quarto works in a way similar to the latter where document each run R code in a separate session. See discussion about this in other discussion like #1045 and linked ones.

For now, you would need to use some explicit caching and object saving + reloading if you want to share data across R sessions in several files.

Regarding parameters, it is supported in Quarto and should be working in Book format also (https://quarto.org/docs/computations/parameters.html). But what you mean is that the parameter is not accessible in other document right ?

It is possible that we need to add support for parameters defined in _quarto.yml which is not possibly yet I think.

@eeholmes
Copy link

eeholmes commented Aug 6, 2022

issue #1712 would solve if the needed shared environments were in adjacent chapters, so like chapter 8 and chapter 9. You could put the chapters in one qmd file.

@andyofsmeg
Copy link
Author

Thanks. An environment option when rendering would be useful. Regarding parameters in a book, yes. I mean the same as with environment variables. I can define within one chapter but they are not passed on. I would like to be able to define parameters centrally and have all chapters be able to access them.

@jjallaire jjallaire modified the milestones: v1.2, Future Aug 14, 2022
@mavam
Copy link

mavam commented Apr 12, 2023

I would like to be able to define parameters centrally and have all chapters be able to access them.

Is this currently possible? Can I pass --execute-params params.yaml with a central params.yaml shared across all chapters?

@al-obrien
Copy link

Having this available from _quarto.yml would be very useful, or some kind of meta file; not sure how far away that feature is yet but would be excited to hear about progress on this.

@cderv
Copy link
Collaborator

cderv commented Oct 18, 2023

For reference the params topic is related to

@mcanouil mcanouil added enhancement New feature or request computations labels Oct 18, 2023
@jonpeake
Copy link

Hi, has there been any development on having parameters passed from the _quarto.yml file? Alternatively, can anyone suggest a workaround for my situation? I'm trying to make a book with a dynamic title and footer based on runtime-defined parameters (i.e., using execute_params command when rendering), but it doesn't render with the parameters passed through that command. It will only render with the "blank" parameters that I pre-define at the beginning of the index.qmd file (that I assume would've been replaced by the runtime parameter values).

@mcanouil
Copy link
Collaborator

@jonpeake The issue is still open and the milestone is set to Future meaning, it is planned but not in a short term timeframe.

Since this is an issue and are asking for something in particular, I suggest you open a discussion and share a concrete small example of your setup, alongside a clear explanation of what your goal is and what you want to achieve.

@jonpeake
Copy link

Thank you for the update, I appreciate it. I'll go ahead and set up a discussion post in the meantime.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
computations enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants