2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AtomでRの文字化けを防ぎたい

Last updated at Posted at 2020-05-22

AtomでRのスクリプトを開くと文字化けする

RguiでRを使っており、基本的にはGUI上で実行しながらスクリプトを書くのですが
「ちょっと直したいな、コメント書きたいな」というときに普段使っているAtomで開くといつも文字化けするし、
いちいち文字コードを手動で選ぶのも面倒なので解決方法はないか調べてみました。

R以外でも「auto-encodingの設定をしたのに上手く動かない!」という方にも有効な解決ではないかと思います。

auto-encodingの設定

まずはこのサイトを参考にauto-encodingの設定をします。
https://rfs.jp/sb/atom-github/auto-encoding.html

atom-1.PNG

Rguiのスクリプトは「shift-jis」の文字コードで保存されているのですが
auto-encodingの設定をするだけでは、「iso88592」と判断されてしまい、まだ文字化けが治りません。

文字コードを不許可にする

[Settings]>[Packages]>[auto-encoding]を検索
さらにauto-encodingの[Settings]を開くとこのような画面になります。

上で紹介したサイトでも触れられていますが、
許可したくない文字コードがある場合は[Disallow some encoding types]に追加することでそれを弾くことができます。

しかし「iso88592」をこれに追加しても今度はutf-8で読まれてしまい、意味がありません。

文字コードを無理やり置き換え

結果的に、[Force some encoding types]にこれを書き加えることで解決しました。
iso88592:shift-jis

atom-2.PNG

Rではありませんが、CSSで同じような問題に直面されていた方のものがありましたのでこちらに載せておきます。
https://github.com/t-ishii/auto-encoding/issues/24

結論

今回はRguiで作成したスクリプトをatomで文字化けなく開く方法についてまとめました。
ちょっと無理やり置き換えているので他で支障がないとも言い切れませんが、基本的に開くスクリプトの種類も限られているので、また問題が発生したら対応すればいいかなと考えています。

RguiやShift-JIS以外でも、auto-encodingが上手くいっていない人はこれらの解決を試してみてはいかがでしょうか。

ちなみに筆者ははじめコマンドからauto-encodingの設定をしたため、auto-encodingの設定がどこにあるのか分からず右往左往しましたので、画像もつけておきました。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?