我想从github中提取子文档,以便在重标记文档中编织子项目。
使用允许子标记文件中的益辉示例,我们可以有一个主文档(修改),它引用github上的子文档,而不是先下载它。
我已经解决了Windows兼容性问题,现在setwd()失败了。
如何正确地设置一个针织品文档以从一个URL中编织子项目?(如果可能的话)
初始(在窗口上)
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这是错误的,因为readLines命令在使用Windows时默认无法访问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中对错误消息没有影响。
发布于 2015-04-06 19:41:53
我认为您不能这样做,因为据我所知,在编织过程中会发生目录更改(对子文档的目录)。因为您的子文档不是本地文件,隐式setwd将失败。
解决方案是添加一个隐藏块,将github文件下载到临时目录,然后删除下载的文件。类似于:
```{r setup, echo=FALSE, results='hide'}setInternet2(use = TRUE)
X <- tempfile(fileext = "Rmd")
on.exit(unlink(x))
download.file("https://raw.githubusercontent.com/yihui/knitr/master/inst/examples/child/knitr-child.Rmd",x“)
```{r test-main, child=x}You can continue your main document below, of course.
```{r test-another}pmax(1:10,5)
发布于 2021-07-02 23:01:18
如果子程序仅被标记(没有需要处理的R代码),那么这可能对您有效。
```{r footer, echo=FALSE, results='asis'}url <- "https://raw.githubusercontent.com/yihui/knitr/master/inst/examples/child/knitr-child.Rmd“
子文本<- readLines(url)
cat(儿童文本,sep="\n")
https://stackoverflow.com/questions/29471545
复制相似问题