git2r::summary() produces different results when called from console and by RStudio

149 views Asked by At

I am trying to write an R package that analyzes Apache Pig GitHub repository with the help of git2r package. I also use testthat package for unit testing.

I have a function, let's call it compute(), which contains code along the lines of:

repo <- repository("C:\normalized\path\to\apache\pig");
allCommits <- commits(repo);
commitSummary <- capture.output(summary(allCommits[[1]]));
print(commitSummary);

The commitSummary is an important part, because I run several regexes on it to recover data like insertions and deletions.

The problem is, when I call compute() from console, it prints out Output 1.

But when compute() is called from my unit test file when I run devtools::test(), it prints out Output 2. (And over the course of me writing this question, after producing Output 2 several times, it produced Output 3.)

When I run the first codeblock in this question from the console, it prints out Output 1, again.

However, when I copy-paste that codeblock into the test file, it prints out Output 3.

I am confused. How is that even possible?

And how can I make sure git2r::summary() uses the format I want?


Output 1

[1] "Commit:  d2de56aad939c7c77324066a6f29cc211e29a077"                                                       
 [2] "Author:  Koji Noguchi <[email protected]>"                                                             
 [3] "When:    2016-12-12 23:07:37"                                                                            
 [4] ""                                                                                                        
 [5] "     PIG-5073: Skip e2e Limit_5 test for Tez (knoguchi)"                                                 
 [6] "     "                                                                                                   
 [7] "     "                                                                                                   
 [8] "     git-svn-id: https://svn.apache.org/repos/asf/pig/trunk@1773899 13f79535-47bb-0310-9956-ffa450edef68"
 [9] "     "                                                                                                   
[10] "2 files changed, 18 insertions, 1 deletions"                                                             
[11] "CHANGES.txt                     | -0 + 2  in 1 hunk"                                                     
[12] "test/e2e/pig/tests/nightly.conf | -1 +16  in 2 hunks"                                                    
[13] ""       

Output 2

[d2de56a] 2016-12-12: PIG-5073: Skip e2e Limit_5 test for Tez (knoguchi)

Output 3

[1] "    Length      Class       Mode " "         1 git_commit         S4 "

Additional notes that might take away from question's clarity

  1. When I load and call the function calling compute() from the unit test file, it prints out Output 1. Same for calling compute() from working directory set to test folder and exactly same arguments.

  2. To make matters more confusing, up until very recently devtools::test() produced Output 1, then it switched to Output 3 before settling on Output 2.

  3. CRAN's documentation for git2r::summary(object, ...) lists following arguments:

    • object The commit object.

    • ... Additional arguments affecting the summary produced.

  4. Accepted values of ... are nowhere to be found.

1

There are 1 answers

1
Dragomok On BEST ANSWER

Turns out, there is probably some sort of a namespace-related race condition going on, since there is already a summary() function in base R (and probably some other packages), which explains why there were 3 different outputs.

I just changed every

summary(commitObject)

into

git2r::summary(commitObject)

and everything seems to work again.