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
enable access to metadata within knit environment #33
Comments
We could also add a metadata parameter to the call to render. This would be a list that is merged with the metadata in the document (sort of like command line parameters overriding config file options). What's cool about this is that you could then write an R function on top of render that is basically just a shim to calling render with arbitrary parameters. |
You could also use it as a report generation tool - i.e. make |
Yes, that's the whole idea! On Fri, Mar 28, 2014 at 12:48 PM, Hadley Wickham
|
Sweet! This is a nice idea! If
Handled similar to how citeproc is in
Then |
How about if we put a bit more explicit structure around this capability. We could create a special object name (e.g. params) and publish the contents of it to the page,e tc. ---
title: my title
params:
foo: bar
data: deafult_data.csv
--- Those would be made available as a "params" object within the knit environment. The render function could then be extended to take a params which would override the YAML. Users could then build functions on top of this to instantiate paramaterized reports, etc. e.g. my_report <- function(data) {
render("my_report.Rmd", params = list(data = data))
} We'd of course lose the ability to access all the metadata but using an explicit construct like "params" might make the feature more comprehensible. We could of course also expose "metadata" with everything to have the best of both worlds. |
Most of the blogging engines allow access to both I think. Might also be nice to allow access to site metadata from output.yaml. But maybe that's already covered by the metadata merging strategy. I'm not sure making params explicit makes things simpler: then if you want to vary the title, you'd need to use a different syntax. (Also I just remembered I need to tell you about |
I see that, my big concern is being able to articulate and use the feature without the conceptual baggage of referring to parameters/variables as "metadata". Of course jekyll, et al just populate the entire Liquid variable scope with the contents of the metadata so you can just say "$title$". We clearly wouldn't want to do that with the R environment so it's got to be one of: metadata$title
variables$title
params$title I think that the second two forms read much nicer but overlay another concept over what's literally just metadata so perhaps not worth it? Let me know if you think we can/should go with one of these forms or just stick with metadata. |
What about |
Okay, I think I'll go with params |
Resolved via 7731784 |
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. |
It would be useful in the code in the Rmd document could easily access
the variables in the yaml metadata. Maybe bind to rmarkdown (or
metadata?) in the global environment when the code is knit?
Then you could do things like:
I can imagine this might be a useful way of parameterising reports so
you only need to change something in one place.
The text was updated successfully, but these errors were encountered: