- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想将 python 与 knitr 一起使用。然而,python block 似乎是单独评估的,并且变量定义在 block 之间丢失。
如何解决?
最小的例子:
---
title: "Minimal example"
---
With a print statement.
```{r hello}
x = 'Hello, Python World!'
print(x)
```
Without a print statement.
```{r world}
print(x)
```
---
title: "Minimal example"
---
With a print statement.
```python
x = 'Hello, Python World!'
print(x)
```
```
Hello, Python World!
```
Without a print statement.
```python
print(x)
```
```
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'x' is not defined
```
#! /usr/bin/Rscript --vanilla
args <- commandArgs(TRUE)
if(length(args) < 1) {
message("Need arguments in the format: %.pymd [%.md]")
q(status=1)
}
name <- substr(args[1],1,nchar(args[1])-4)
if(length(args) < 2) {
args[2] <- paste0(name,".md")
}
library(knitr)
opts_chunk$set(engine = 'python')
res <- try(knit(args[1], args[2]))
if(inherits(res, "try-error")) {
message("Could not successfully knit RMD (or PYMD) to MD")
q(status=1)
} else q()
现在运行:
./knit2py.r test.pymd test.md
最佳答案
是的,确实,knitr 目前无法为 R 以外的语言评估跨多个 block 的代码拉伸(stretch)。解决方案不是使用 knitr,而是使用 pweave。对源文件的修改很少:
---
title: "Minimal example"
---
With a print statement.
<<>>=
x = 'Hello, Python World!'
print(x)
@
Without a print statement.
<<>>=
print(x)
@
The end.
现在运行:
pweave -f pandoc test.mdw
pweave 上有注释的网站上说使用 python3 的 pip 安装会失败。不过,我在简单运行时完全没有问题:
pip install pweave
pip install markdown
也许,这只是一张旧纸条。
关于python - 将 python 与 knitr 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40171949/
我正在用 Bookdown 写一份报告,我有兴趣水平地复制一系列图片,并用一个描述所有图片的标题。如果我不定义 fig.cap,我会得到正确的图片,如下所示: ```{r, out.width = "
我用过dplyr对于某些分析和特定代码,完成操作大约需要 30 秒。在生成的 HTML 中,我得到了类似这样的很长的输出(再现最后几行): |=============================
我的 last two问题只是令人尴尬,但我相信这是真正的交易。我的系统是新安装的,所以除了操作系统之外的版本都是最新的:Windows 7 SP1、R-3.0.1、Lyx 2.0.6、knitr 1
我找不到将语法上可接受的 RStudio 样式折叠插入外部 R 代码文件的方法,该文件设置为从 knitr 文档中使用。或者我错过了什么。有几种方法可以做到这一点:1) 允许代码头,例如: ## @k
我有一个包含以下代码的小书本“书”: A concept map is a diagram that shows 'ideas' and the relationship between those
像这样的东西,但它不起作用: ```{r examples, engine="bash"} export EXAMPLES="example/path" ``` ```{r example1,
我是 latex 和 knitr 的新手,当我使用 echo=FALSE 时,R block 的输出有问题。下面的 .Rnw 代码按预期工作,即输出有 1. some code 2.
有没有办法使用 .Rmd 文件 直接在 Jupyter 中?换句话说,有没有办法让 jupyter 渲染这样的文件:https://github.com/yihui/knitr-examples/bl
是否可以在 markdown 文件中使用 knitr 的 pandoc() 函数和嵌入的 pandoc 配置来更改默认的 pandoc latex 模板选项? 例如,如果我在 foo.md 的开头使用
我不熟悉使用 rmarkdown 和 knitr 来制作 .docx word 文档。 rmarkdown 引用指南指出,使用 -- 给出一个破折号,而 --- 给出一个破折号。 如果我将我的 .Rm
我想知道是否有一种自动化的方法可以使评论不打印在输出中。现在,我正在使用以下内容来省略评论: >= ## load relimp package library(relimp) ## calculat
我已经根据文档在 Knitr 上添加了自定义语言引擎。 require(knitr) knit_engines$set(upper = function(options) { code <- pa
我正在使用 Rmarkdown 生成一个 PDF 文档,我想在其中手动定义图形编号。 下面是一个 block 的例子: ```{r chunk26, fig.cap = "Fig. 5.3 My fi
这可能是一个极端情况,但我正在尝试使用 knitr 创建一个投影仪演示文稿,我想在其中使用不同的公式作为函数的参数来显示代码块。我发现当使用覆盖时,代码块中的波浪号消失了。有没有办法让它们显示? 这是
我尝试编译 YiHui 的 BIG5 example (有中文内容的knitr)。我使用了 Mac OSX snowleopard、最新的 RStudio、pdfLatex(结果与 XeLatex 相
这听起来像是一个愚蠢的问题,但是当我使用 RStudio 服务器从 Rmd 文件编译 pdf 文档时,我想知道 .tex 文件保存在哪里。 我添加了 keep_tex 选项,因此 Rmd 的标题如下所
在 knitr可以在代码块中使用其他语言。例如,我们可以使用: ```{python} Some python code ``` 我们可以使用 R引擎内联`r一些R代码` 中是否可以使用其他语言?内联
例如,在编写演讲幻灯片时,我们经常会遇到这样一种情况,我们希望内联代码输出为 source code = result。 .所以例如 "foofoofoo qt(p = 0.95, df = 24)
有没有办法,在 knitr 中将 fig.cap 移动到图形上方?我需要上面的它们,以便当为某个表选择图列表的超链接时,它会导航到图。 Right now the caption and thus h
如果它在同一目录中,我可以对子文档使用以下代码。 >= @ 如果子文档不在主文档的同一目录中,我想知道如何使用子文档。预先感谢您的帮助和时间。 最佳答案 这可以被认为是一个错误。现在我已经把它修好了
我是一名优秀的程序员,十分优秀!