このブログの更新は Twitterアカウント @m_hiyama で通知されます。
Follow @m_hiyama

メールでのご連絡は hiyama{at}chimaira{dot}org まで。

はじめてのメールはスパムと判定されることがあります。最初は、信頼されているドメインから差し障りのない文面を送っていただけると、スパムと判定されにくいと思います。

参照用 記事

Rコードの編集のために、ESSをトリアエズで入れた

Rの編集のためにEmacsのR-modeを探しました。ESS(Emacs Speaks Statistics)というのが定番らしいのですが、これは単純なシンタックスハイライトというレベルのものじゃなくて、かなり大規模なアドオンパッケージです。

お手軽なのがいいなー、とか思いながらも、ESSのサイト http://ess.r-project.org/ からアーカイブファイルess-15.03-1.zipをダウンロード。このアーカイブファイルを展開したら282個のファイルが出現しました。ウヒャ。

トップレベディレクトリにMakefileがあったので、とりあえずmake。そしたら:


LANG=C texi2dvi --pdf ess.texi
You don't have a working TeX binary installed, but the texi2dvi script
can't proceed without it. If you want to use this script, you have to
install some kind of TeX, for example the MikTeX package from
http://miktex.org/ (which is not part of the typical MSYS environment).
make[1]: *** [ess.pdf] Error 1
make[1]: Leaving directory `/cygdrive/c/Users/hiyama/Work/configs/emacs/ess-15.0
3-1/doc'
make: *** [all] Error 2

texi2dviとか入れてないからそりゃ失敗するわな。"which is not part of the typical MSYS environment"と言っているので、MSYSで実行しているのは知っているんですね。

Makefileを読んでみると:

## This is the default target, i.e. 'make' and 'make all' are the same.
all install uninstall: $(ETC_FILES)
	cd etc; $(MAKE) $@
	cd lisp; $(MAKE) $@
	cd doc; $(MAKE) $@

docサブディレクトリのmakeが失敗してるようだけど、まーいいや、etcとlispは出来てるようだから先に進みましょう。

make -n install してみると、/usr/share/emacs/ の下に色々入れようとしているので、どうせ失敗するのでこれはパス。ディレクトリ ess-15.03-1/ を、~/.emacs.d/modules/ の下にマルっと移動。これでも何とかなるでしょう。

ess-15.03-1/lisp/ がロードパスに入っていれば、(require 'ess-site) でESSの準備が出来るようなので、それならば、と (load-file "~/.emacs.d/modules/ess-15.03-1/lisp/ess-site.el") で直接ロード。これでも、R-mode は使えるようになりました。

インデントが4桁なのが深すぎるので、(setq ess-indent-level 2) 、だが効かない。どうもスタイルという概念があって、各種インデントはスタイルとしてまとめて設定するようです。(setq ess-default-style 'スタイル名) でセットするか、対話的にやりたいなら (ess-set-style) を使います。ess-set-styleのキーバインドは C-c C-e C-s、3ストローク覚えられねー。

ややこしいことに、DEFAULTという名前のスタイルがデフォルトになってなくて、初期設定のスタイルはRRRです(RRRが何の略号かは知らない)。(setq ess-default-style 'DEFAULT) としました。デフォルトではなかったDEFAULTスタイルでは、インデントが2桁です。スタイルの情報は、ess-custom.el内のess-style-alist変数に定義されています。

Rコードのコメントの所でTABキーを押してみたら、コメントが右に飛んでしまう。これは何だ? コメントの配置に関しては次のルールがあるそうです( http://ess.r-project.org/Manual/ess.html#Indenting )。

  • By default, comments beginning with ‘###’ are aligned to the beginning of the line.
  • Comments beginning with ‘##’ are aligned to the current level of indentation for the block containing the comment.
  • Finally, comments beginning with ‘#’ are aligned to a column on the right (the 40th column by default, but this value is controlled by the variable comment-column,) or just after the expression on the line containing the comment if it extends beyond the indentation column.

Emacs-Lispのインデントスタイルと同じルール。このインデントスタイルは、(setq ess-fancy-comments nil) でオフにできるそうですが、それがRの習慣なら従うことにしましょう。

もう少しマシな設定は使いながら…。