Extracting git information in rstudio

81 views Asked by At

I'm trying my hand at some reproducible research in RStudio and with Rmarkdown. Mostly because I'm too lazy to paste figures into powerpoint or word over and over. grin

One thing that I think is very important with reproducible research is recording exactly which version of the RMarkdown document produced the report. Often such documents go through many revisions, and in addition, they might pull in multiple other source files or data from the repository. So, insert the git commit SHA, and record if the repository is clean or dirty.

But despite RStudio knowing about git, it doesn't seem to make this information available through any API calls. Or am I missing something?

Other than shelling out to git by hand, what are my options?

1

There are 1 answers

1
Tutuchan On BEST ANSWER

I don't think RStudio provides this information either but you can retrieve it easily with a system call like this, for example :

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

You just have to specify the format you want in git log and maybe fiddle a bit with git statusto get the exact information you want.