R CMD CHECK 和 @examples — check() 的失败与否取决于注释。

huangapple go评论62阅读模式
英文:

R CMD CHECK and @examples -- check() fails or not depending on a comment

问题

我正在使用 devtools 开发一个 R 包,我的 @examples 部分出了问题。我无法相信,但目前我处于这样一个情况,如果我添加或删除示例中的注释,要么它将无错误地通过 check(),要么会出现似乎不可能的错误,或者至少是与我的代码似乎不相关的错误。

这个示例通过 check(),没有错误:

# @examples
# jetsh = read_net(iac_example("jets_sharks.yaml"))
# jetsh = set_external(jetsh, "Ken", 1.0)
# jetsh = iac::cycle(jetsh, ncycles = 100)
# #
# plot_log(jetsh, roi=c("Ken", "_Ken", "jets", "sharks", "burglar", "bookie"),
# main="Ken is a burgling Shark")

但下面的版本失败了!注意关于 Ken 的较长注释。我已经多次复制了这个问题,包括在 check() 之间重新启动 R 会话。

# @examples
# jetsh = read_net(iac_example("jets_sharks.yaml"))
# jetsh = set_external(jetsh, "Ken", 1.0)
# jetsh = iac::cycle(jetsh, ncycles = 100)
# # Ken is a burglar in the Sharks, what is retrieved from his name
# plot_log(jetsh, roi=c("Ken", "_Ken", "jets", "sharks", "burglar", "bookie"),
# main="Ken is a burgling Shark")

来自 R CMD CHECK 的错误消息似乎不相关。我看到了零星的类似错误报告,但没有这个:

  > base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv)
  > base::cat("read_net", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t")
  > ### * <FOOTER>
  > ###
  > cleanEx()
  > options(digits = 7L)
  > base::cat("Time elapsed: ", proc.time() - base::g
  + Error: unexpected end of input
  Execution halted

示例代码无论 check() 状态如何都可以正常运行。进一步令人沮丧的是,我还有另一个使用相同 @examples 的函数,从未在 check() 期间生成错误。

非失败版本在 GitHub 上:'rob-ward-psych/iac'(文件 iac_network.R 中的 read_net())。非常感谢帮助解决这个问题。

英文:

I'm using devtools to develop an R package and I'm having trouble with my @examples. I can't believe it, but currently I'm in a place where if I add or remove a comment from the example, it will either check() with no errors, or halt with what seems like an impossible error, or at least one that seems impossible to relate to my code.

This example check()'s with no errors:

#&#39; @examples
#&#39; jetsh = read_net(iac_example(&quot;jets_sharks.yaml&quot;))
#&#39; jetsh = set_external(jetsh, &quot;Ken&quot;, 1.0)
#&#39; jetsh = iac::cycle(jetsh, ncycles = 100)
#&#39; #
#&#39; plot_log(jetsh, roi=c(&quot;Ken&quot;, &quot;_Ken&quot;, &quot;jets&quot;, &quot;sharks&quot;, &quot;burglar&quot;, &quot;bookie&quot;),
#&#39; main=&quot;Ken is a burgling Shark&quot;)

But the version below fails! Note the longer comment about Ken. I've replicated this several times, including restarting the R session between check()'s

#&#39; @examples
#&#39; jetsh = read_net(iac_example(&quot;jets_sharks.yaml&quot;))
#&#39; jetsh = set_external(jetsh, &quot;Ken&quot;, 1.0)
#&#39; jetsh = iac::cycle(jetsh, ncycles = 100)
#&#39; # Ken is a burglar in the Sharks, what is retrieved from his name
#&#39; plot_log(jetsh, roi=c(&quot;Ken&quot;, &quot;_Ken&quot;, &quot;jets&quot;, &quot;sharks&quot;, &quot;burglar&quot;, &quot;bookie&quot;),
#&#39; main=&quot;Ken is a burgling Shark&quot;)

The error message from R CMD CHECK doesn't seem relevant. I've seen scattered reports of similar errors, but not this one:


  &gt; base::assign(&quot;.dptime&quot;, (proc.time() - get(&quot;.ptime&quot;, pos = &quot;CheckExEnv&quot;)), pos = &quot;CheckExEnv&quot;)
  &gt; base::cat(&quot;read_net&quot;, base::get(&quot;.format_ptime&quot;, pos = &#39;CheckExEnv&#39;)(get(&quot;.dptime&quot;, pos = &quot;CheckExEnv&quot;)), &quot;\n&quot;, file=base::get(&quot;.ExTimings&quot;, pos = &#39;CheckExEnv&#39;), append=TRUE, sep=&quot;\t&quot;)
  &gt; ### * &lt;FOOTER&gt;
  &gt; ###
  &gt; cleanEx()
  &gt; options(digits = 7L)
  &gt; base::cat(&quot;Time elapsed: &quot;, proc.time() - base::g
  + Error: unexpected end of input
  Execution halted

The example code runs fine regardless of check() status. Further frustrating is that I have another function using the same @examples, and it has never generated an error during check().

The non-failing version is on git-hub: &#39;rob-ward-psych/iac&#39; (read_net() in the file iac_network.R). Any help running this down is greatly appreciated.

答案1

得分: 3

这看起来像是一个devtools::check的bug。使用devtools::check时,我遇到了与你相同的错误,但如果我构建.tar.gz文件,然后运行:

R CMD check iac_0.1.0.tar.gz

我就不会遇到错误。如果你在使用RStudio,你可以在项目选项中默认使用标准的检查方法:取消勾选Build tools | Use devtools package functions if available

编辑以添加:

我对devtools::check进行了一些调试,以找出问题所在。我认为这实际上不是一个devtools::check的bug。它调用了常规的R CMD check并使用了--timings选项;如果我在直接调用R CMD check时添加这个选项,我会遇到相同的错误。看起来这是因为iac_example()函数在其示例部分调用了file.edit()函数而触发的。我不知道为什么注释的形式会有所不同,但通常最好将对file.edit()的调用条件化为交互执行,即写成:

if (interactive())
  file.edit(iac_example("what_where.yaml"))
英文:

That looks like a devtools::check bug. I get the same error as you using devtools::check, but if I build the .tar.gz file and then run

R CMD check iac_0.1.0.tar.gz

I get no error. If you're using RStudio, you can default to the standard check method in a project option: uncheck Build tools | Use devtools package functions if available.

EDITED to add:

I did some debugging of devtools::check to find out what was going wrong. I don't think this is actually a devtools::check bug. It calls the regular R CMD check with the --timings option; if I add that option when I call R CMD check directly, I get the same error. It appears to be triggered because the iac_example() function has a call to file.edit() in its examples section. I don't know why the form of the comment makes a difference, but it would generally be a good idea to make the call to file.edit() conditional on interactive execution, i.e. write

if (interactive())
  file.edit(iac_example(&quot;what_where.yaml&quot;))

huangapple
  • 本文由 发表于 2023年6月30日 02:42:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76583828.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定