Convert yacas output to R
Closed this issue · 3 comments
ggrothendieck commented
Is there an easier way to convert res
to R?
library(Ryacas)
eq <- "((2300+1900*1)+(x+2300+1900*1)*0.002)/(600-400)==1"
res <- solve(ysym(eq), "x")
eval(yac_expr(res)[[1:3]]) # convert to R
## [1] -2004200
mikldk commented
Thanks, @ggrothendieck . I would use the utility functions y_rmvars()
and as_r()
to do it like this:
library(Ryacas)
eq <- "((2300+1900*1)+(x+2300+1900*1)*0.002)/(600-400)==1"
res <- solve(ysym(eq), "x")
res
#> {x==(-0.80168e6)/0.4}
x_res <- y_rmvars(res)
x_res
#> {(-0.80168e6)/0.4}
as_r(x_res)
#> [1] -2004200
I am not sure if you also think that is easier? I think it is easier to read.
ggrothendieck commented
Yes. That is much better. No mucking with internals.
mikldk commented
Good to hear that.