Skip to content
Prev 30647 / 398525 Next

trying to plot function using curve

Faheem Mitha wrote:
[Code snipped]

Some comments:
- Indeed, I'd use curve(), but of course you can do it "manually"
   with plot(.., type="l") as well.
- In your usage of curve() you rely heavily on R's scoping rules
   (should work, from my point of view, but always looks a bit
   dangerous):
       densityfn <- function(x) density(x,theta,pos,len) # No defaults!
       # Now curve() grabs theta, pos, len from any environment before:
       curve(densityfn)
- I would not use that many functions as in your code,
   but that's a matter of taste.
- It's not that amusing to debug all that code - try it yourself,
   R has many nice debugging tools (debug(), browser(), etc.).

Uwe Ligges