RobinHankin / mvp

https://robinhankin.github.io/mvp/
8 stars 3 forks source link

bug in mvp_to_spray() with constant #14

Closed RobinHankin closed 5 years ago

RobinHankin commented 5 years ago

If there is a constant in a mvp object, mvp_to_spray() should work as expected, but returns an error:

> mvp_to_spray(as.mvp("1+x+y"))
Error in `[<-`(`*tmp*`, i, sapply(v, function(x) { : 
  invalid subscript type 'list'

NB: mvp_to_spray(as.mvp("x+y")) works fine.

RobinHankin commented 5 years ago

Related problems:

> a
mvp object algebraically equal to
1  +  x
> constant(a) <- 0
> a
mvp object algebraically equal to
0  +  x
> dput(a)
structure(list(names = list(character(0), "x"), power = list(
    integer(0), 1L), coeffs = c(0, 1)), class = "mvp")

This is a bug in constant<-.mvp(): the value returned was not "cleaned" by mvp(), so the returned value has a zero-coefficient term. It's a relatively benign bug because the extra term is mathematically equal to zero. But it causes problems with mvp_to_spray().