Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running via Rscript fails #32

Closed
HarlanH opened this issue Jan 23, 2012 · 10 comments
Closed

running via Rscript fails #32

HarlanH opened this issue Jan 23, 2012 · 10 comments

Comments

@HarlanH
Copy link

HarlanH commented Jan 23, 2012

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
@hadley
Copy link
Member

hadley commented Jan 23, 2012

Failure with Rscript but not R, usually indicates that I've forgotten to declare a base R package dependency.

@floybix
Copy link

floybix commented Feb 9, 2012

Seems to be something to do with ReferenceClasses...

$ Rscript -e "library(testthat); library(methods); SummaryReporter$new"
NULL

whereas the same in an interactive session prints out a class method definition. But I can't see any difference in the sessionInfo() between the two cases, arrgh

@hadley
Copy link
Member

hadley commented Feb 9, 2012

It works with R -e, but not with Rscript, but I don't see any differences in sessionInfo either:

public : R -e "library(testthat); sessionInfo()"
> library(testthat); sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] testthat_0.6

loaded via a namespace (and not attached):
[1] evaluate_0.3 plyr_1.7.1   stringr_0.6 
> 
> 
public : Rscript -e "library(testthat); sessionInfo()"
R version 2.14.1 (2011-12-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] testthat_0.6

loaded via a namespace (and not attached):
[1] evaluate_0.3 plyr_1.7.1   stringr_0.6 

@hadley
Copy link
Member

hadley commented Feb 9, 2012

Oh, except that methods is missing, and order seems to matter:


Rscript -e "library(methods); library(testthat); SummaryReporter\$new"Class method definition for method new()
function (...) 
{
    methods::new(def, ...)
}
<environment: 0x102fe10a8>

 Methods used:  
    "methods", "new"

@markmfredrickson
Copy link

I think this bug is still live. I've install_githubed from master.

I run auto test via R -e from within a Makefile, though it also occurs in interactive sessions. I think it cropped up when I upgraded 2.14, though I'm not actually sure.

testthat will run the tests initially just fine. If I change the source documents, the tests are properly restarted and run. However, when I change a test file, I get:

Rerunning tests:  test.testStatistics.R 
Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : 
  "new" is not a valid field or method name for reference class “SummaryReporter”

While not necessarily the cleanest test case, you can run my tests via:

$ git clone git@github.com:markmfredrickson/RItools.git
$ cd RItools
$ make autotest
... add a space to tests/test.*

@xuanxu
Copy link

xuanxu commented Jun 7, 2012

I'm still having this bug with R 2.15.0 and testthat 0.6. when running a script via Rscript

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

With a simple tests.R using test_dir():

#!/usr/bin/env Rscript
library("testthat")
test_dir("distributions/tests/")

+1 to reopen the issue.

@hadley hadley reopened this Jun 8, 2012
@hadley
Copy link
Member

hadley commented Jun 8, 2012

@xuanxu - you need the development version from github.

@markmfredrickson - that sounds like a different bug (which I'm pretty sure I've also fixed)

@hadley hadley closed this as completed Jun 8, 2012
@markmfredrickson
Copy link

@markmfredrickson - that sounds like a different bug (which I'm pretty sure I've also fixed)

Confirmed. Thanks!

@xuanxu
Copy link

xuanxu commented Jun 8, 2012

Thanks @hadley, is there a new version release planned anytime soon?

@hadley
Copy link
Member

hadley commented Jun 18, 2012

Yes, hopefully in the next week or two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants