1

When assigning class types to fields in Reference Classes, what is the specification for numeric that allows for NAs? For example, if I use the following code and try to assign a value of NA to the field extinctTime, I receive an error stating:

Error: invalid assignment for reference class field ‘extinctTime’, should be from class “numeric” or a subclass (was class “logical”)

I know there is likely a simple solution to permit the inclusion of NA extinction times for field extinctTime, but any advice would be great.

simClass <- setRefClass(
  Class = 'simClass',
  fields = list(
    ...
    extinct = 'logical',
    extinctTime = 'numeric'
    ... 
  )
)
Peter
  • 11
  • 2
  • 3
    Maybe assign `NA_real_` not `NA` (which is of class logical). A more general solution would be `as(NA,class(your_thing))` – Frank Aug 10 '15 at 18:37
  • 1
    @Frank, yeah...I was hoping something along these lines would work in reference classes, but it errors out and says: class “NA_real_” for field ‘extinctTime’ is not defined. I've tried a few iterations of this without any success. – Peter Aug 11 '15 at 00:01
  • 1
    Ahhh, nevermind @Frank, I see what you're saying and it appears to have worked! I was looking at the problem from the wrong perspective! Thanks for the help. – Peter Aug 11 '15 at 00:05
  • Np, good luck with your project! – Frank Aug 11 '15 at 00:05

0 Answers0