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

Key n is mapped to FALSE in simple example #122

Open
ramiromagno opened this issue Oct 18, 2022 · 9 comments
Open

Key n is mapped to FALSE in simple example #122

ramiromagno opened this issue Oct 18, 2022 · 9 comments

Comments

@ramiromagno
Copy link

{yaml} package version is 2.3.6.

library(yaml)

x <- "
n: 100
"
  yaml.load(x)
#> $`FALSE`
#> [1] 100
@ramiromagno
Copy link
Author

ramiromagno commented Oct 18, 2022

Okay, I just realised there are some special values in YAML. n stands for "not", is it? It seems that quoting it works as I expected. Is that the way to escape its special meaning?

I'd prefer to not force the user to quote the data in the YAML file. I can I somehow tell yaml.load_file() to treat n literally?

@spgarbet
Copy link
Member

This is a quirk of yaml 1.1. It's removed for yaml 1.2, but efforts to get that up and going aren't going so fast.

@spgarbet
Copy link
Member

It might be possible to write a custom boolean handler. I've not tried that.

The parser returns a "bool#yes" and "bool#no" for these tag types. It might be possible to modify this behavior.

Try writing a custom handler and post your code here. If that works, I'll see if it can become an option to ignore in the parser output.

@spgarbet
Copy link
Member

spgarbet commented Oct 18, 2022

This seems to work:

yaml.load("'n': false\ntrue: 200", 
                handlers=list(boolean=
                    function(x) if(x %in% c('n','y')) x else tolower(x)=='true'))

@ramiromagno
Copy link
Author

Thanks for your answers. But it seems that only works because the input has n quoted, i.e. 'n'.

@spgarbet
Copy link
Member

That slipped through in my example. I just tried it and upstream it's emitted a T/F for this, so I don't see an easy way. It'll require compiler modification.

@ramiromagno
Copy link
Author

Okay, thanks for trying. I'll leave this issue open, but feel free to close it if you think this functionality is unlikely to be supported.

@spgarbet
Copy link
Member

It is the plurality of issues opened. The other being requests for yaml 1.2 (which doesn't have the n/y issue). I've started an experiment to use the libfyaml library and see if it solves both problems.

@r2evans
Copy link

r2evans commented Feb 28, 2023

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