Home > OS >  How to convert equation from R code into readable text?
How to convert equation from R code into readable text?

Time:07-14

I have defined multiple different functions, each containing one equation each, like so:

catalanFormula <- function(n){
    return( (factorial(2 * n)) / ((factorial(n   1)) * factorial(n)) )
  }
triangularFormula <- function(n){
    return( (n * (n 1)) / 2 )
}

I am then plotting each function using the plot() function from base R. What I want to do is be able to include the equation in my plot as a label or text, but in a way that is easily understandable. I know I can use LaTeX to write each equation manually, but I was wondering if there is a package or method anyone knows of that can deparse a mathematical equation in R and turn it into a standard readable mathematical equation. The only math occurring is factorials, multiplication, division, exponents, addition, and subtraction.

For example, I want to convert

(factorial(2 * n)) / ((factorial(n   1)) * factorial(n))

into something that looks like catalanFormula triangularFormula

This solution is highly specific to the functions you need to transform. But it could be extended if needed.

  •  Tags:  
  • r
  • Related