在 rstudio 中提取 git 信息

Extracting git information in rstudio

我正在尝试在 RStudio 和 Rmarkdown 中进行一些可重现的研究。主要是因为我懒得一遍又一遍地将数字粘贴到 powerpoint 或 word 中。 咧嘴一笑

我认为对于可重复研究非常重要的一件事是准确记录 哪个 版本的 RMarkdown 文档生成了报告。此类文档通常会经过多次修订,此外,它们可能会从存储库中提取多个其他源文件或数据。因此,插入 git 提交 SHA,并记录存储库是干净的还是脏的。

但是尽管 RStudio 知道 git,但它似乎无法通过任何 API 调用提供此信息。还是我遗漏了什么?

除了手动支付 git,我还有什么选择?

我认为 RStudio 也不提供此信息,但您可以通过这样的 system 调用轻松检索它,例如:

docVersion <- system("git log -n 1 --pretty=oneline", intern = TRUE)
repoStatus <- system("git status -s", intern = TRUE)

您只需要在 git log 中指定您想要的格式,也许 fiddle 稍微 git status 以获得您想要的确切信息。