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

Allow YAML comments to be preserved by yaml.load() #68

Closed
richierocks opened this issue Feb 4, 2019 · 3 comments
Closed

Allow YAML comments to be preserved by yaml.load() #68

richierocks opened this issue Feb 4, 2019 · 3 comments

Comments

@richierocks
Copy link

Currently, YAML comments are always stripped by yaml.load(). For example

yaml.load('tag: value # a comment')
## $tag
## [1] "value"

I'm trying to programmatically update lots of yaml files, and these contain useful comments. It would be helpful to me to be able to preserve them.

?yaml.load hints that it may be possible to specify a handler function to deal with this, but it isn't clear how exactly to go about it.

Please can you either allow a way to preserve YAML comments or document the process.

@spgarbet
Copy link
Member

spgarbet commented Feb 4, 2019

The parser code used does not emit tokens for comments. The handlers exist only for what the parser emits by token name. This would have to pushed upstream to the libyaml authors. See line 872 of scanner.c.

@viking
Copy link
Contributor

viking commented Sep 9, 2019

Closing since this is more of a libyaml issue as @spgarbet mentioned.

@viking viking closed this as completed Sep 9, 2019
@viking
Copy link
Contributor

viking commented Sep 9, 2019

Switching YAML libraries may happen in the future, at which time this issue can be addressed again. However, it may be useful to add a way to as.yaml to emit comments. The YAML parser, however, ignores them. A patch to libyaml would be required to change that.

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

No branches or pull requests

3 participants