-1

I've tried finding this on SO without any luck:

How do I convert a closure object into a string in R?

I have a list of functions, like this:

functions = c(function(x) 2*x, function(x) sin(x*pi), function(x))

And, I iterate over them like for (func in functions){..., and I'd like to be able print the function expression as part of my plotting.

I've tried:

toString(eval(func))
as.character(eval(func))

What gives?

Related links:

Community
  • 1
  • 1
buzzinolops
  • 311
  • 1
  • 3
  • 7

1 Answers1

0

There seems to be no easy way to accomplish this. Here is the best way I found:

as.character(parse(text=as.list(func)))

For a more general solution, you can capture the output, as @chinsoon said.

buzzinolops
  • 311
  • 1
  • 3
  • 7