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

Encoding problem with rstudioapi::getActiveDocumentContext() #28

Closed
GegznaV opened this issue Oct 5, 2016 · 4 comments
Closed

Encoding problem with rstudioapi::getActiveDocumentContext() #28

GegznaV opened this issue Oct 5, 2016 · 4 comments

Comments

@GegznaV
Copy link

GegznaV commented Oct 5, 2016

In R Studio editor I selected the following lines of code (pay attention to international symbols):

"ą ž ū ų š č"
context <- rstudioapi::getActiveDocumentContext();

and pressed "Run" button to run the code. When I printed context$selection, the result was:

Document Selection:
- [6, 1] -- [8, 18]: '"Ä… ž Å« ų Å Ĩ"\ncontext <- rstudioapi::getActiveDocumentContext();\ncontext$selection <...>'

I expected "ą ž ū ų š č" instedad of `"Ä… ž Å« ų Å Ĩ".

Is it possible to make rstudioapi::getActiveDocumentContext() to read international symbols correctly?

Session info ----------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.1 (2016-06-21)
 system   x86_64, mingw32             
 ui       RStudio (1.0.34)            
 language (EN)                        
 collate  Lithuanian_Lithuania.1257   
 tz       Europe/Helsinki             
 date     2016-10-05                  

Packages --------------------------------------------------------------------------------------------------------------
 package    * version date       source                             
 curl         2.1     2016-09-22 CRAN (R 3.3.1)                     
 devtools     1.12.0  2016-06-24 CRAN (R 3.3.1)                     
 digest       0.6.10  2016-08-02 CRAN (R 3.3.1)                     
 git2r        0.15.0  2016-05-11 CRAN (R 3.3.0)                     
 httr         1.2.1   2016-07-03 CRAN (R 3.3.1)                     
 magrittr   * 1.5     2014-11-22 CRAN (R 3.3.0)                     
 memoise      1.0.0   2016-01-29 CRAN (R 3.2.3)                     
 R6           2.1.3   2016-08-19 CRAN (R 3.3.1)                     
 rstudioapi * 0.6     2016-07-20 Github (rstudio/rstudioapi@55d3200)
 spAddins     0.1.5   2016-07-12 local                              
 withr        1.0.2   2016-06-20 CRAN (R 3.3.1)        
@GegznaV
Copy link
Author

GegznaV commented Oct 5, 2016

I tried to debug the problem and found lines .Call("rs_getEditorContext", 0L) which I was not able to debug further.

@GegznaV GegznaV closed this as completed Oct 5, 2016
@GegznaV GegznaV reopened this Oct 5, 2016
@kevinushey
Copy link
Contributor

Does it help if you manually reset the encoding?

ctx <- rstudioapi::getActiveDocumentContext()
Encoding(ctx$contents) <- "UTF-8"

@GegznaV
Copy link
Author

GegznaV commented Oct 6, 2016

A modification of code @kevinushey provided worked:

ctx <- rstudioapi::getActiveDocumentContext()
Encoding(ctx$selection[[1]]$text) <- "UTF-8"

@hadley
Copy link
Member

hadley commented May 31, 2017

@kevinushey should this be fixed on the R side or elsewhere? If on the R side, I'm happy to do a PR.

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