【问题标题】:parse does not return attributes in Rstudio test environment and Travis解析在 Rstudio 测试环境和 Travis 中不返回属性
【发布时间】:2016-12-24 01:53:45
【问题描述】:

parseMe只有一个功能

parseMe <- function(text) {
    parsed = parse(text = text)
    str(parsed) #for diagnosis
    getParseData(parse(text = parsed))
}

这个函数是用testthat测试的

test_that('parseMe',{
    expect_that(parseMe('print("hey")'), is_a('data.frame'))
})

如果从 Rstudio 命令行以交互方式运行 devtools::test(),则此测试通过。然而,在 Rstudio 测试环境 (v0.99.892) 中(从“构建”选项卡进行测试时),此测试失败,因为 parse 函数无法返回属性(由于 str 而在测试输出中可见)。同样的测试在 travis-ci 上也失败了。这是什么原因?怎么解决?

以下是我使用的最小测试包和 travis 测试日志的链接

【问题讨论】:

  • 这确实是个问题。为什么不回答?
  • 我自己就是这么做的。你写的话我就接受了

标签: r unit-testing parsing testthat


【解决方案1】:

只有在parse(..., keep.source = TRUE) 时才会保留这些属性。根据?parse 文档,keep.source 的默认值来自getOption("keep.source")。默认选项值可能与以交互方式和非交互方式运行 R 不同。如果要始终保留源,则应确保将其设置为 TRUE。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 2014-11-19
    • 2011-06-28
    • 2019-06-29
    • 2019-02-22
    • 1970-01-01
    • 2013-03-27
    相关资源
    最近更新 更多