rstudio- r脚本中的一些非标准特殊字符自行更改
我偶尔使用数据帧,其中使用了非传统特殊字符,这些字符看起来与Rstudio内置的观看功能中的标准字符相同。我在脚本中参考这些字符,但是有时在打开文件时,这些字符已更改为脚本中的标准键盘字符。
例如,在我的脚本中,'
更改标准撇号'
和-
更改标准连字符 - - 。
这些脚本是我必须定期运行的脚本,因此每次都必须手动纠正这是一件琐事。我也没有弄清楚触发rstudio进行这些更改是什么。我尝试关闭和重新打开以测试这是否是触发器,并且角色仍然正确。它似乎只有在我关闭计算机后才发生。
有人知道这和/或是什么原因引起的吗? TIA
编辑:我需要这样做的原因是我导出到编码UTF-8的CSV。
I occasionally work with data frames where unorthodox special characters are used that look identical to standard characters in RStudio's in-built viewing functionality. I refer to these characters in my scripts, but sometimes when I open the file, these characters have been changed to standard keyboard characters within the script.
For example, in my script, ’
changes to a standard apostrophe '
and –
changes to a standard hyphen -
.
These scripts are ones I have to run regularly, so having to manually correct this each time is a chore. I also haven't worked out what it is that triggers RStudio to make these changes. I've tried closing and reopening to test if that's the trigger, and the characters have remained correct. It only seems to happen after I've turned off my computer.
Does anyone know of a workaround for this and/or what is causing this? TIA
EDIT: the reason I need to do this is I export to csv which is UTF-8 encoded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方法,尽管我欢迎对此任何缺点的任何反馈。
如果您已经编写了代码(包括特殊字符):
单击文件>保存使用编码...>显示所有编码> Unicodefffe
重新打开文件时,
现在:单击文件>用编码重新打开...>显示所有编码> unicodefffe
如果您尚未编写代码,则应该是从开始使用Unicodefffe编码(上面的指令)从开始之前保存文件的情况。
I've found a workaround, although I welcome any feedback on any drawbacks to this.
If you have already written your code (including the special characters):
Click File > Save with Encoding... > Show all encodings > unicodeFFFE
Now when you reopen the file:
Click File > Reopen with Encoding... > Show all encodings > unicodeFFFE
If you haven't already written your code, it should just be a case of saving your file from the start with the unicodeFFFE encoding (instructions above) before you write the code and then using the reopen with encoding option whenever you open the file.