You function isn't vectorized. At the moment it will only take a single scalar input and output a single return value. curve
expects that it should be able to feed in a vector of the x values it wants to plot for and should receive a vector of response values. The easiest solution is to just use Vectorize
to automatically convert your function into one that can take vector inputs.
f2 <- Vectorize(f)
curve(f2, -pi, pi, n = 100)
However, you might just want to write a vectorized version of the function directly.