2012-12-10 26 views
11

私はRマークダウンファイル用のジキル変換器を書こうとしています。 RMarkdownConverter.rbを作成し、_pluginsディレクトリに配置しました。他のプラグインが動作していることを確認しましたが、このプラグインは動作していません。私も自分自身に入れたものを含め、エラーメッセージは表示されません。これは使用されていないようです。しかし、ジキルは私の.Rmdファイル用のHTMLファイルを生成していますが、単にRチャックをコードチャックとして処理しています。どんな助けや考えも大歓迎です。ジキル変換Rマークダウン

RMarkdownConverter.rbファイル:

module Jekyll 
    class RMarkdownConverter < Converter 
     safe true 
     priority :low 

    def setup 
     STDERR.puts "Setting up R Markdown..." 
     return if @setup 
     require 'rinruby' 
     @setup = true 
    rescue 
     STDERR.puts 'do `gem install rinruby`' 
     raise FatalException.new("Missing dependency: rinruby") 
    end 

     def matches(ext) 
      ext =~ /Rmd/i 
     end 

     def output_ext(ext) 
      '.html' 
     end 

     def convert(content) 
     setup 
     STDERR.puts "Using R Markdown..." 
     R.eval "require(knitr)" 
     R.eval "render_markdown(strict=TRUE)" 
     R.assign "content", content 
     STDERR.puts content 
     R.eval "out <- knit(text=content)" 
     R.eval "print(out)" 
     end 
    end 
end 

私の最初のRマークダウンポストの内容:

--- 
layout: post 
title: Using (R) Markdown, Jekyll, and Github for Blogging 
published: true 
tags: R R-Bloggers Jekyll github 
type: post 
status: publish 
--- 

First, we need to install [RinRuby](https://sites.google.com/a/ddahl.org/rinruby-users/) to call R from Ruby. In the terminal, execute: 

    gem install rinruby 

First R chuck: 

```{r} 
2 + 2 
``` 

答えて

4

は、私はあなたが必要だと思う以下

R.assign "content", content 
R.eval "knitr::render_markdown(strict = TRUE)" 
R.pull "(knitr::knit2html(text = content, fragment.only = TRUE))" 

で最後の数行を交換してみてくださいR.pullを実行して、R出力の内容をRubyにコピーします。さらに、Rmdからhtmlに直接変換することをお勧めします。私はこの戦略を、別のルビーベースのブログプラットフォームであるRuhohと協力して成功裏に使用しました。

更新。非常に奇妙ですが、拡張子rmdを使用するとmdと競合するようです。私はそれをランダムにramに変更し、ジキルは正しくそれを拾うようだ。なぜ私は分からない。

+0

'_config.yml'に' markdown_ext:markdown'を追加すると、Jekyllは 'rmd'ファイルを処理します。ただし、 'md'ファイルは処理されません。 '.markdown'というファイル拡張子を使っているので、私にとって大きな問題ではありません。 – jbryer

+0

遅くなることが知られている 'rinruby'を起動することなくこれを行う方法があります。私は、Rmdファイルを処理するためにシェルコマンドを直接使用する方法を模索していますが、knitrが使用するバックティックはシェルの実行を引き上げます。 – Ramnath