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

Consider supporting an 'include' directive #46

Closed
eddelbuettel opened this issue Oct 20, 2017 · 4 comments
Closed

Consider supporting an 'include' directive #46

eddelbuettel opened this issue Oct 20, 2017 · 4 comments
Labels

Comments

@eddelbuettel
Copy link

In a number of use cases, YAML files are carried over from other, similar files. An example may be YAML frontmatter for Rmarkdown files: certain formatting aspects (say, particular to an author or institution) are copied around from project to project.

In other languages, common elements can re-use by means of an #include somefile statement.
And at least one other YAML parser implements this in the context of a larger system for home automation.

This carried over from here and subsequent email discussion. Having an include directive is yaml is probably easier than attempting to change pandoc or rmarkdown, and the issue really is local to the yaml frontmatter.

/cc @aaronwolen

@viking
Copy link
Contributor

viking commented Dec 20, 2017

The easiest way to accomplish this right now is through the use of a !include tag and a custom handler:

yaml.load_file("test.yml", handlers = list(include = function(fn) yaml.load_file(fn)))

That would only work for 1 level deep, but you could create a wrapper function to do infinite recursion:

foo <- function(...) yaml.load_file(..., handlers = list(include = foo))
foo("test.yml")

@eddelbuettel
Copy link
Author

Nice. One level may actually be good enough for us.

@viking viking added the feature label Dec 27, 2017
@spgarbet
Copy link
Member

Can be done via handlers.

@eddelbuettel
Copy link
Author

Can be done via handlers.

It's been years since I would have needed this but I am still curious so how? Can you post a short example, here or in the package?

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

No branches or pull requests

3 participants