Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting git information in rstudio

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?

like image 624
namelessjon Avatar asked Nov 17 '25 18:11

namelessjon


1 Answers

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.

like image 132
Tutuchan Avatar answered Nov 19 '25 09:11

Tutuchan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!