Fetching git info in rstudio

I am trying to use some reproducible research in RStudio and Rmarkdown. Mainly because I'm too lazy to paste shapes into powerpoint or word over and over again. grin

One thing that I think is very important in replicable research is a record of which version of the RMarkdown document produced the report. Often such documents go through many changes and, in addition, they can check out many other source files or data from the repository. So, paste in git commit SHA and write if the repository is clean or dirty.

But even though RStudio is aware of git, it looks like this information is not available through any API calls. Or am I missing something?

Also, to manually truncate git, what are my options?

+3


source to share


1 answer


I don't think RStudio provides this information either, but you can get it easily with a call system

like:

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

      



You just need to specify the format you want in git log

, and maybe play around a bit git status

to get the information you want.

+1


source







All Articles