我喜欢将包含多个 R Markdown 和 Markdown 文件的存储库上传到 github。
这是一个 example of such a markdown file on github .这是一个屏幕抓取。
问题是图像不显示。您可以单击图像,然后您将转到存储文件的位置。
引用的文件是:
https://github.com/... /blob/.../myfigure.png
而我认为它需要引用
https://github.com/... /raw/.../myfigure.png
我考虑的事情:
imgur:我可以通过添加以下代码来使用外部图像托管(例如, see this example ):
```{r setup}
opts_knit$set(upload.fun = imgur_upload) # upload all images to imgur.com
````
但是,由于各种原因,我不想这样做(我在防火墙后面上传时遇到问题;它很慢;它会产生不必要的依赖)
Rpubs:还有RPubs这很酷。但是,在发布时它似乎更适合单个 Markdown 文档而不是多个 R markdown 文档。并且它没有在源 R Markdown 和 Markdown 文档之间提供如此紧密的链接。
题
最佳答案
这曾经是最小示例的一部分,请使用
opts_knit$set(base.url='https://github.com/.../raw/.../')
查看更改 here和 here .
另见 http://yihui.name/knitr/options .
编辑 [更新以将 base.url 恢复为以前的值
关于切换,您可以将函数定义为
create_gitpath <- function(user, repo, branch = 'master'){
paste0(paste('https://github.com', user, repo, 'raw', branch, sep = '/'),'/')
}
my_repo <- create_gitpath(user, repo)
knit.github <- function(..., git_url ){
old_url <- opts_knit$get('base.url')
on.exit(opts_knit$set(base.url = old_url))
opts_knit$set(base.url = git_url)
knit(..., envir = parent.frame())
}
运行
knit
直到你想推送到 github
然后运行 knit.github(..., git_url = my_repo)
关于r - 如何在不使用外部图像托管的情况下在从 knitr 生成的 github 上的 Markdown 中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11237715/