Skip to content
Back to formatted view

Raw Message

Message-ID: <763D8CCC-9705-492C-BE3C-987775407512@comcast.net>
Date: 2017-02-01T23:57:45Z
From: David Winsemius
Subject: Using a mock of an S4 class
In-Reply-To: <C7338A7EFF31BB4D831BB06C00887789B9C015A8@MBX023-W1-CA-2.exch023.domain.local>

> On Feb 1, 2017, at 11:46 AM, Ramiro Barrantes <ramiro at precisionbioassay.com> wrote:
> 
> Hello,
> 
> I have a function that applies to an S4 object which contains a slot called @analysis:
> 
> function calculation(myObject) {
>  tmp <- myObjects at analysis
>  result <- ...operations on analysis...
>  return result
> }
> 
> I am writing a unit test for this function.  So I was hoping to create a mock object but I can't figure out how to do it:
> 
> test_that("test calculation function", {
>  mockMyObject<- mock(?????)  #I am not sure what to put here
>  r<-calculation(mockMyObject)
>  expect_true(r,0.83625)
> })
> 
> How can I create a mock S4 object??

I'm not seeing a class definition for any "S4"-classed object. I would expect you to have used `setClass`. I believe that once the class is defined that you should have access to the `new` constructor function.

> 
> Thanks in advance,
> Ramiro
> 
> 	[[alternative HTML version deleted]]

R-help is a plain-text mailing list.

--

David Winsemius
Alameda, CA, USA