juliaの特徴をRユーザの視点から眺める

juliaアドベントカレンダー17日目です。

Rの仕様書を読む前に読んでおきたいAdvanced Rの翻訳が来月出るという話はもう16回くらいしてきた。

R言語徹底解説

R言語徹底解説

で、その本の中にRを使うなら知っておきたい関数やデータセットがVocabularyという形でまとめられている。
http://adv-r.had.co.nz/Vocabulary.html
これと同じことをjuliaでやってアドベントカレンダーの記事にしようと思ったら既に昨年のアドベントカレンダーでまとまっていたぜ。やることなくなったぜ。
http://bicycle1885.hatenablog.com/entry/2014/12/01/050522

juliaの特徴についてつらつら書く

仕方がないのでjulia公式トップにある特徴について思うところをつらつら書く。
たまにR使ってる人に聞かれるんだけど、「速い。とにかく速い。」としか答えてこなかったのでここでまとめておきたい。

Multiple dispatch: providing ability to define function behavior across many combinations of argument types

これを一番上に書くというのは一番の目玉ということなのだろうか。
そしてこれはRの場合、S3クラスのディスパッチで実装してることになるのかな。

Dynamic type system: types for documentation, optimization, and dispatch

Rは型がないから…

Good performance, approaching that of statically-compiled languages like C

RだってRcppを使えば…
でも普通に書くとjulia公式トップにあるような結果になる。そしてjuliaでも速くするコツはあるようで。
http://bicycle1885.hatenablog.com/entry/2015/01/04/175916

Built-in package manager

これはRも大丈夫。install.packagesでOK。
Pythonも個人的にはパッケージマネージャがあるという理由でAnaconda使ってるからなあ。

Lisp-like macros and other metaprogramming facilities

最初juliaのコードを読んで@が出てきてなんじゃこれと思って調べた憶えがある。@はマクロなんだけど非常に検索しづらい。
そしてRにマクロはない。

Call Python functions: use the PyCall package

これは便利。Arduinoいじってる時にjuliaはシリアル通信どうなんかなと思って調べたらPySerialをそのまま使ってるパッケージがあってなるほどと思った。
https://github.com/sjkelly/SerialPorts.jl
Rだと最近はPythonInRパッケージが便利。これでChainerもTensorflowも動く(という報告がある)。
http://yamano357.hatenadiary.com/entry/2015/10/13/033135

Call C functions directly: no wrappers or special APIs

RもAPIは用意されてるけどRcppの方が楽だろうな。
http://adv-r.had.co.nz/C-interface.html

Powerful shell-like capabilities for managing other processes
Designed for parallelism and distributed computation
Coroutines: lightweight “green” threading
User-defined types are as fast and compact as built-ins
Automatic generation of efficient, specialized code for different argument types
Elegant and extensible conversions and promotions for numeric and other types

この辺はパフォーマンスの話だけどとりあえずRに無いものがたくさんあるんだなという印象。

Efficient support for Unicode, including but not limited to UTF-8

juliaではコードに寿司が使えるというのは有名な話。
http://bicycle1885.hatenablog.com/entry/2014/12/05/011256
Rの場合、出力はできるけどコードには使えない。

MIT licensed: free and open source

Rの場合、ライセンスはGPL-2または3らしい。

最後に

ちなみにRワカラングという溜まり場があるけど、これはjuliaワカラングに触発されて作られたはず。
https://github.com/JuliaTokyo/julia-wakalang
そして土曜日はjulia tokyoですね!
http://juliatokyo.connpass.com/event/21715/
juliaハンズオンもあって親切だ(私は舞台があって行けないんだけど)。
ぜひRユーザー諸氏はbicycle1885さんの薫陶を受けてきてほしい。

enjoy!!!