【问题标题】:cryptic error message in testthattestthat 中的神秘错误消息
【发布时间】:2014-11-09 02:00:44
【问题描述】:

我在 Rstudio (Windows 0.98.1056) 中运行 testthat,我收到以下错误。它似乎是在我更新 Rstudio 和安装的 R 包之后出现的,但我怀疑这两者可能没有直接关系。该错误也发生在一个非常简单的测试文件上。有人遇到过吗?

文件:tests/test-all.R

library(testthat)
library(matrixUtils)
test_package("matrixUtils")

文件:tests/testthat/matrixUtils-test.R

context("testa")
test_that("subsetting by one dimension", {
  a <-1 
  expect_equal(a, 1)
})

错误信息:

==> Sourcing R files in 'tests' directory

Error: '\.' is an unrecognized escape in character string starting "'\." Execution halted

Exited with status 1.


sessionInfo() R version 3.1.1 (2014-07-10) Platform: x86_64-w64-mingw32/x64 (64-bit)

locale: [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages: [1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages: [1] magrittr_1.1.0  matrixUtils_0.2 testthat_0.8.1  dplyr_0.2.0.99  reshape2_1.4    ggplot2_1.0.0   gridExtra_0.9.1 [8] zoo_1.7-11     

loaded via a namespace (and not attached):  [1] assertthat_0.1   colorspace_1.2-4 digest_0.6.4     gtable_0.1.2     lattice_0.20-29  MASS_7.3-34      munsell_0.4.2     [8] parallel_3.1.1   plyr_1.8.1     proto_0.3-10     Rcpp_0.11.2      scales_0.2.4     stringr_0.6.2    tools_3.1.1     
>

【问题讨论】:

  • 你应该证明一个reproducible example。不要只是粘贴错误消息,显示您正在运行的生成消息的代码。创建一个示例,我们可以运行该示例以得到与您相同的错误,否则我们真的无法确定是什么原因造成的。
  • 除非我共享整个软件包,否则您的建议不太可行。但我很乐意分享测试代码。照原样提出问题仍然很有用:通常我可以在不知道代码的情况下说出构建/测试错误中的问题。
  • 我建议您调试您的代码以生成一个最小的可重现示例。继续发布“非常简单的测试文件”,以便我们运行与您相同的东西。此错误消息似乎非常特定于字符串。如果没有具体的例子,我真的不明白你在这里期待什么样的答案。
  • 这个问题是否只发生在test_package() 上?如果您只在示例文件中使用test_file() 会怎样? (到目前为止,我一直无法重现。)
  • 我正要在 github 上发布这个包,但我验证了这个包在 Linux 上测试成功,但在 Windows 上没有。这似乎是一个重要的系统特定问题。

标签: r testthat


【解决方案1】:

没有包就很难检查你的错误。一些想法:

这是 github/hadley/testthat 上的 similar error reported in #187

  1. 更新测试包。最新版本是 0.9.1。 问题已关闭,但看起来很难重现。 @hadley 建议修复

    检查是否在 RStudio 的项目选项下启用了 devtools

    renkun-ken 在他的 Rprofile 中添加了 library(devtools) 作为最后的手段。

    我在没有运行库(devtools)的 .Rprofile 的情况下启动 RStudio。测试包中的测试不起作用,然后我按照您的建议运行 devtools::test() ,它可以工作。

  2. 如果这不起作用。 检查您的路径并使用file.path() 在您的包中使用字符串创建路径。 This error 似乎突然出现指定错误的路径。

希望这对 gappy 有所帮助,并且您很快就会收到“哇”的快乐测试消息!

M

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-29
    • 2015-09-04
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多