是否可以在knitr输出中包含R文档?使用库存数据集时,只需包含内置文档而不必复制并粘贴它就会很好.问题似乎是?副作用,因此没有意义上的"结果".例如,
```{r}
?mtcars
```
Run Code Online (Sandbox Code Playgroud)
没有被knitr困住的输出.
使用help(...,help_type)而?不是帮助.我试过了:
```{r, results='markup'}
help(mtcars, help_type="text")
```
Run Code Online (Sandbox Code Playgroud)
和
```{r, results='asis'}
help(mtcars, type="html")
```
Run Code Online (Sandbox Code Playgroud)
结果相同.(在后一种情况下,knitr确实捕获了输出## starting httpd help server ... done,这基本上只是关于副作用的消息.)
换句话说,有没有办法在纯文本或HTML中提取R帮助?
re.search()在演示 Python 的正则表达式功能时,我编写了一个小程序来比较,re.findall()和的返回值re.finditer()。我知道re.search()每行只能找到一个匹配项,并且re.findall()只返回匹配的子字符串,而不返回任何位置信息。然而,我很惊讶地发现这三个函数之间的匹配子字符串可能不同。
代码(可在 GitHub 上获取):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# License: CC-BY-NC-SA 3.0
import re
import codecs
# download kate_chopin_the_awakening_and_other_short_stories.txt
# from Project Gutenberg:
# http://www.gutenberg.org/ebooks/160.txt.utf-8
# with wget:
# wget http://www.gutenberg.org/ebooks/160.txt.utf-8 -O kate_chopin_the_awakening_and_other_short_stories.txt
# match for something o'clock, with valid numerical time or
# any English word with proper capitalization
oclock = re.compile(r"""
(
[A-Z]?[a-z]+ # word mit max. 1 capital letter
| …Run Code Online (Sandbox Code Playgroud)