0
$\begingroup$

I would like to convert Mathematica code to R code. For example,

4/(-1 + δ) + (-1 + δ) Subscript[P, R]

The above is a copy version from Matematica. But I would like to type this one in R such as:

4/(-1 + Delta) + (-1 + Delta)*PR

Of course, the example is very simple to convert directly to R, but some complicated equations are not easy to covert it.

Could you please let me know how to automatically convert to R code?

$\endgroup$
  • 2
    $\begingroup$ Do you just mean that you want the special symbols to resolve to a plain name and subscripts to unwrap as if there were no subscript? $\endgroup$ – b3m2a1 Jul 3 '18 at 18:03
  • $\begingroup$ Yes and * or / . Mathematica usually doesn't need to have * . But R should have it! $\endgroup$ – Sam Kim Jul 3 '18 at 18:49
  • 3
    $\begingroup$ My suggestion is to start with a simple pattern-matching replacement of Subscript via ReplaceAll then hit the resultant expression with ToString[..., CForm] $\endgroup$ – b3m2a1 Jul 3 '18 at 20:11
  • $\begingroup$ Thank you so much b3m2a1! $\endgroup$ – Sam Kim Jul 5 '18 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.