Jekyll转换器为R Markdown

jbr*_*yer 11 r jekyll knitr r-markdown

我正在尝试为R Markdown文件编写一个Jekyll转换器.我创建RMarkdownConverter.rb并将其放在我的_plugins目录中.我已经验证其他插件正在运行,但这个不是.我也没有看到任何错误消息,包括我自己放置的消息.似乎没有使用它.但是,Jekyll正在为我的.Rmd文件生成一个HTML文件,但只是将R chuck作为代码查询处理.任何帮助或想法将不胜感激.

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
Run Code Online (Sandbox Code Playgroud)

我的第一个R Markdown帖子的内容:

--- 
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
```
Run Code Online (Sandbox Code Playgroud)

Ram*_*ath 4

尝试用以下内容替换最后几行

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

我认为你需要R.pull将 R 输出的内容复制到 Ruby。此外,我建议直接从 Rmd 转换为 html。我在与Ruhoh合作时成功地使用了这个策略,Ruhoh 是另一个基于 Ruby 的博客平台。

更新。这很奇怪,但使用扩展名 rmd 似乎与 md 冲突。我随机将其更改为ram,jekyll 似乎正确地选择了它。我不知道为什么。