hadley/test_that — Issue #32: running via Rscript fails
Author: HarlanH
Created: 2012-01-23 14:20:30+00:00
State: open

This script (rscript_test.R):

#!/usr/bin/Rscript

library(testthat)

a <- data.frame(x=1:3, y=4:6)
b <- data.frame(x=1:3, y=5:7)

context('rscript test')

test_that('dfs match',
expect_equivalent(a, b)
)

works when sourced or run in batch mode:

hharris test> R CMD BATCH ./rscript_test.R
hharris test> !cat
cat rscript_test.Rout

R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> #!/usr/bin/Rscript
>
> library(testthat)
>
> a <- data.frame(x=1:3, y=4:6)
> b <- data.frame(x=1:3, y=5:7)
>
> context('rscript test')
>
> test_that('dfs match',
+	expect_equivalent(a, b)
+ )
Error: Test failure in 'dfs match'
a not equal to expected
Component 2: Mean relative difference: 0.1666667
Execution halted

But fails when run via Rscript:

hharris test> ./rscript_test.R
Error in context("rscript test") : attempt to apply non-function
Execution halted

Similar scripts with a test_dir() have failed with a slightly more useful errors:

Error in find_reporter(reporter) : attempt to apply non-function
Calls: test_dir -> find_reporter
Execution halted