【发布时间】:2015-04-06 12:41:51
【问题描述】:
我想从 github 拉取子文档,作为 rmarkdown 文档中的子项编织。
使用来自allowing child markdown files 的yihui 的示例,我们可以有一个主文档(修改后),它引用github 上的子文档,而不是先下载它。
我已经解决了一个 Windows 兼容性问题,现在收到 setwd() 失败。
如何正确设置 knitr 文档以从 URL 编织子项? (如果可能)
初始(在 Windows 上)
You can also use the `child` option to include child documents in markdown.
```{r test-main, child='https://raw.githubusercontent.com/yihui/knitr/master/inst/examples/child/knitr-child.Rmd'}
```
You can continue your main document below, of course.
```{r test-another}
pmax(1:10, 5)
```
错误输出
## Quitting from lines 4-4 (https://raw.githubusercontent.com/yihui/knitr/master/inst/examples/child/knitr-child.Rmd)
## Error in readLines(if (is.character(input2)) { :
## cannot open the connection
## Calls: <Anonymous> ... process_group.block -> call_block -> lapply -> FUN -> knit -> readLines
## In addition: Warning message:
## In readLines(if (is.character(input2)) { : unsupported URL scheme
## Execution halted
这是错误的,因为在 Windows 上运行时 readLines 命令默认无法访问 HTTPS。
v2(在 Windows 上)
为了纠正 readLines 问题,我添加了一个块,增加了访问 HTTPS 的能力
You can also use the `child` option to include child documents in markdown.
```{r setup, results='hide'}
setInternet2(use = TRUE)
```
```{r test-main, child='https://raw.githubusercontent.com/yihui/knitr/master/inst/examples/child/knitr-child.Rmd'}
```
You can continue your main document below, of course.
```{r test-another}
pmax(1:10, 5)
```
错误输出
## processing file: https://raw.githubusercontent.com/yihui/knitr/master/inst/examples/child/knitr-child.Rmd
## Quitting from lines 2-2 (https://raw.githubusercontent.com/yihui/knitr/master/inst/examples/child/knitr-child.Rmd)
## Quitting from lines NA-7 (https://raw.githubusercontent.com/yihui/knitr/master/inst/examples/child/knitr-child.Rmd)
## Error in setwd(dir) : cannot change working directory
## Calls: <Anonymous> ... process_group.inline -> call_inline -> in_dir -> setwd
## Execution halted
尝试将setwd("~") 添加到块setup 对错误消息没有影响
【问题讨论】:
标签: r knitr r-markdown