Skip to content

Instantly share code, notes, and snippets.

@kohske
Created October 10, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohske/3e438a7962cacfef9d32 to your computer and use it in GitHub Desktop.
Save kohske/3e438a7962cacfef9d32 to your computer and use it in GitHub Desktop.
Seamless Python In RMarkdown
---
title: "RMarkdownでPythonInR"
author: '@kohske'
date: "2015年10月10日"
output: html_document
---
参考 https://speakerdeck.com/yamano357/tokyor51-lt
フック
```{r include=FALSE}
library(knitr)
library(PythonInR)
c2s = function(before, options, envir) {
if (before) {
} else {
v=pyExecg(paste0(options$code, collapse="\n"))
for (n in names(v)) assign(n, v[[n]], envir)
}
}
knit_hooks$set(py = c2s)
```
パイソンチャンク
```{r, eval=FALSE, py=TRUE, include=FALSE}
a=range(0, 3)
b=range(0, 5)
```
使ってみる
```{r}
a
b
expand.grid(a, b)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment