I work with multivariate polynomials using the "mpoly" package. I am given a multivariate polynomial with known dimension, but unknown in advance coefficients. Then I need to multiply this polynomial by a function and evaluate the product. The problem is when a variable vanishes in a polynomial, after applying as.function()
I get the unused arguments error while evaluating the function. The following code illustrates the problem:
library(mpoly)
p1<-mp("2*x+4*y+z")
f1<-as.function(p1, vector = F)
f1(1,2,3)
>13
p2<-mp("0*x+0*y+0*z")
f2<-as.function(p2, vector = F)
f2(1,2,3)
>Error in f2(1, 2, 3) : unused arguments (2, 3)
Here I expect f2
to return 0.
I am new to R, and I would appreciate any ideas/help. Thanks in advance!