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

Character encoding #4

Closed
daroczig opened this issue Jan 16, 2013 · 15 comments
Closed

Character encoding #4

daroczig opened this issue Jan 16, 2013 · 15 comments

Comments

@daroczig
Copy link

Is there any chance to create an UTF-8 encoded yaml string on an UTF-8 locale? It seems that the returned string is somehow Unicode (at least it seems):

> as.yaml(list('é'))
[1] "- \"\\xE9\"\n"

Converting "back" the yaml to R works fine, but I would like to see rather something like this:

> as.yaml(list('é'))
[1] "- é\n"

My session info:

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8    
 [5] LC_MONETARY=en_US.utf8    LC_MESSAGES=en_US.utf8   
 [7] LC_PAPER=C                LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     utils     datasets  grDevices graphics  methods   base     

other attached packages:
[1] yaml_2.1.5
@viking
Copy link
Contributor

viking commented Jan 17, 2013

Thanks for your report. I've added a new option to the as.yaml function to escape unicode or not (default is don't escape).

@daroczig
Copy link
Author

Awesome, thanks a lot for that new feature!

@aL3xa
Copy link

aL3xa commented Jan 18, 2013

Thanks for the fix! =)

@viking
Copy link
Contributor

viking commented Jan 18, 2013

I've submitted the new version to CRAN. Hopefully it'll be accepted soon.

@viking
Copy link
Contributor

viking commented Jan 18, 2013

The new version is up on CRAN. Thanks again for your bug reports. :)

@daroczig
Copy link
Author

Wow, CRAN maintainers are just as quick as you :)
Thanks again, keep up the great work!

@reinholdsson
Copy link

@viking Thank you for an excellent package, it is really useful. However, running yaml_2.1.7 on Windows I can't get the above examples to work on my computer?

> as.yaml(list('é'))
Error in as.yaml(list("é")) : 
  Emitter error: expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS
> as.yaml(list('é'), unicode = F)
Error in as.yaml(list("é"), unicode = F) : 
  Emitter error: expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS
> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252   
[3] LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C                   
[5] LC_TIME=Swedish_Sweden.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
 [1] yaml_2.1.7        pmtools_0.1       stringr_0.6.2    
 [4] RCurl_1.95-4.1    bitops_1.0-6      RJSONIO_1.0-3    
 [7] httr_0.2          whisker_0.3-2     RODBC_1.3-8      
[10] devtools_1.3      data.table_1.8.10

loaded via a namespace (and not attached):
[1] digest_0.6.3   evaluate_0.4.7 formatR_0.9    knitr_1.5     
[5] markdown_0.6.3 memoise_0.1    parallel_3.0.1 tools_3.0.1   

@viking
Copy link
Contributor

viking commented Nov 19, 2013

OK, I'll check it out.

@reinholdsson
Copy link

Thanks!

@ofurkusi
Copy link

ofurkusi commented Feb 3, 2016

This does not seem to have been fully resolved. I experience the issue that @reinholdsson reports with version 2.1.13, running on Windows 7, R version 3.0.2.

> as.yaml(list("é"))
Error in as.yaml(list("é")) : 
  Emitter error: expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Icelandic_Iceland.1252  LC_CTYPE=Icelandic_Iceland.1252    LC_MONETARY=Icelandic_Iceland.1252 LC_NUMERIC=C                      
[5] LC_TIME=Icelandic_Iceland.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] yaml_2.1.13

loaded via a namespace (and not attached):
[1] tools_3.0.2

@ofurkusi
Copy link

ofurkusi commented Feb 3, 2016

As a follow up I would like to add that if an associative object is passed to as.yaml(), the error message seems to be muted and the resulting object takes the value of the variable key. Examples:

> as.yaml(list(special.char = "é"))
[1] "special.char: special.char\n"
> as.yaml(list(
+   ascii.chars = "ascii only string that works",
+   special.chars = "þðöá"))
[1] "ascii.chars: ascii only string that works\nspecial.chars: special.chars\n"

@viking
Copy link
Contributor

viking commented Nov 8, 2017

This may be fixed now. I've written some tests and they seem to pass. Do you mind trying the latest version in master?

@viking
Copy link
Contributor

viking commented Nov 8, 2017

By the way, the pull request that changed how UTF-8 is read is here: #40

@viking
Copy link
Contributor

viking commented Nov 8, 2017

@daroczig @ofurkusi I'll go ahead and close this and reopen if if you're still having problems.

@viking viking closed this as completed Nov 8, 2017
@viking
Copy link
Contributor

viking commented Nov 8, 2017

@reinholdsson If you're still having trouble, please open a new issue. Thanks!

viking added a commit that referenced this issue Nov 8, 2017
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

5 participants