从控制台和RStudio调用时,git2r :: summary()会产生不同的结果 [英] git2r::summary() produces different results when called from console and by RStudio

查看:213
本文介绍了从控制台和RStudio调用时,git2r :: summary()会产生不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个R软件包,该软件包可在 Apache Pig GitHub存储库中借助 git2r 包。我还使用 testthat 包进行单元测试。



我有一个函数,我们称之为 compute(),其中包含以下代码:

  repo<  -  repository C:\\\
ormalized\path\to\apache\pig);
allCommits< - 提交(回购);
commitSummary< - capture.output(summary(allCommits [[1]]));
print(commitSummary);

commitSummary 是一个重要的部分,因为



问题在于,当我调用 compute()从控制台输出,它输出 Output 1



但是当 compute()在我运行 devtools :: test()时从我的单元测试文件中调用,它将输出 Output 2 。 (在我制作这个问题的过程中,在生成 Output 2 几次之后,它生成了 Output 3 。)



当我从控制台运行这个问题中的第一个代码块时,它会再次输出 Output 1 然而,当我将该代码块复制粘贴到测试文件中,它将输出 Output 3

我很困惑。这怎么可能?



我如何确保 git2r :: summary()使用格式I想要吗?




输出1



  [1]Commit:d2de56aad939c7c77324066a6f29cc211e29a077
[2]作者:Koji Noguchi< knoguchi@apache.org>
[3]When:2016-12-12 23:07:37
[4]
[5]PIG-5073:跳过e2e Limit_5测试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个文件已更改,18个插入,1个删除
[11]更改。 txt | -0 + 2 in 1 hunk
[12]test / e2e / pig / tests / nightly.conf | -1 +16 in 2 hunks
[13]



输出2 < h2>

  [d2de56a] 2016-12-12:PIG-5073:跳过Te2(knoguchi)e2e Limit_5测试



输出3



  [ 1]长度班级模式1 git_commit S4






< h3>可能从问题清晰度中删除的其他注释


  1. 当我加载并调用调用在单元测试文件中计算(),它将输出 Output 1 。对于从工作中调用 compute()目录设置为测试文件夹和完全相同的参数。

  2. 更麻烦的是,直到最近 devtools :: test() 生成输出1 ,然后在输入2 之前切换到输出3

    li>
  3. CRA N的文档 git2r :: summary(object,...)列出以下参数:
    $ b




    • 对象提交对象。


    • ... 影响生成汇总的其他参数。




  4. 接受的值 ...


解决方案

原来,可能会出现某种与命名空间相关的竞争条件,因为在基本R中已经有 summary()函数(并且可能还有其他一些软件包),这就解释了为什么有3个不同的输出。

我只是改变了每一个

pre $ summary $(commitObject)

转换为

  git2r :: summary(commitObject)

并且所有内容似乎都可以再次运行。


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 <knoguchi@apache.org>"                                                             
 [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.

解决方案

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.

这篇关于从控制台和RStudio调用时,git2r :: summary()会产生不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆