parse does not return attributes in Rstudio test environment and Travis

85 views Asked by At

The package parseMe has a single function

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

this function is tested using testthat

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

If one runs devtools::test() interactively from the Rstudio command line, this test passes. In the Rstudio testing environment however (v0.99.892) (when testing from the "build" tab) this test fails because parse function fails to return the attributes (visible on test output due to str). The same test also fails on travis-ci. What is the reason for this? How can it be solved?

Below are the links to the minimal test package that I use and travis testing log

1

There are 1 answers

0
MrFlick On BEST ANSWER

The attributes are only retained if parse(..., keep.source = TRUE). The default value for keep.source comes from getOption("keep.source") as per the ?parse documentation. It's likely that the default option value is different run running R interactively vs non-interactively. If you want to always keep the source, you should make sure to set that to TRUE.