testthat: invalid replacement for field 'context_open'

26 views
Skip to first unread message

Nacho Caballero

unread,
Feb 20, 2013, 1:07:05 PM2/20/13
to rdev...@googlegroups.com

I'm getting this error when testing my package


> test("my_package")

Error in function (value)  :

  invalid replacement for field ‘context_open’, should be from class “logical” or a subclass (was class “character”)

This works

> SummaryReporter

Generator object for class "SummaryReporter":

Class fields:

Name:       context         test       failed context_open     failures            n    has_tests
Class:    character          ANY      logical      logical         list      integer      logical

 Class Methods:
    "add_result", "add_result#Reporter", "callSuper", "copy", "end_context", "end_context#Reporter", "end_reporter",
"end_reporter#Reporter", "end_test", "export", "field", "getClass", "getRefClass", "import", "initFields", "initialize", "show",
"start_context", "start_context#Reporter", "start_reporter", "start_reporter#Reporter", "start_test", "trace", "untrace",
"usingMethods"

 Reference Superclasses:
    "Reporter", "envRefClass"

but this doesn't

> SummaryReporter$new()

Error in function (value)  :
  invalid replacement for field ‘context_open’, should be from class “logical” or a subclass (was class “character”)

Any ideas?

Hadley Wickham

unread,
Feb 20, 2013, 1:10:58 PM2/20/13
to Nacho Caballero, rdev...@googlegroups.com
Hi Nacho,

I think you'll need to provide more context than that - why are you
trying to do SummaryReporter$new(), and what do your tests look like?

Hadley
> --
> You received this message because you are subscribed to the Google Groups
> "devtools" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rdevtools+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Chief Scientist, RStudio
http://had.co.nz/

Nacho Caballero

unread,
Feb 20, 2013, 1:17:55 PM2/20/13
to Hadley Wickham, rdev...@googlegroups.com
I don't need to do `SummaryReporter$new()`, I was just trying to understand where the error was coming from.

It's my first package, so maybe I'm doing something wrong: https://github.com/nachocab/clickme

Nacho Caballero

unread,
Feb 21, 2013, 2:45:03 PM2/21/13
to rdev...@googlegroups.com, Hadley Wickham
No ideas? I really wanted to start using testthat

> For more options, visit https://groups.google.com/groups/opt_out.
>
>



Winston Chang

unread,
Feb 21, 2013, 3:07:57 PM2/21/13
to Nacho Caballero, rdev...@googlegroups.com, Hadley Wickham
I just took a look at your code... the problem is that you defined a function called quote(), which probably is getting in the way of testthat using R's quote function. If you comment that out, the tests will run.

This sounds like a bug in testthat -- but it's also probably a good idea to avoid writing functions with the same name as base R functions.

-Winston


To unsubscribe from this group and stop receiving emails from it, send an email to rdevtools+...@googlegroups.com.

Hadley Wickham

unread,
Feb 21, 2013, 3:09:47 PM2/21/13
to Winston Chang, Nacho Caballero, rdev...@googlegroups.com
> I just took a look at your code... the problem is that you defined a
> function called quote(), which probably is getting in the way of testthat
> using R's quote function. If you comment that out, the tests will run.

Possibly, except that quote() isn't used in testthat, as far as I can tell.

Hadley

Winston Chang

unread,
Feb 21, 2013, 3:23:37 PM2/21/13
to Hadley Wickham, Nacho Caballero, rdev...@googlegroups.com
Hm, yeah, it definitely has something to do with the quote function. I think maybe some other function (called indirectly by test_that()) calls quote(), and is being evaluated in the wrong environment, so that it picks up the modified version. I'll file an issue on it.

Nacho Caballero

unread,
Feb 22, 2013, 10:01:02 AM2/22/13
to Winston Chang, Hadley Wickham, rdev...@googlegroups.com
Wow, thank you. I would have never caught that. Did you get an intuition and tried commenting out the quote function, or did you find out some other way?
Reply all
Reply to author
Forward
0 new messages