Argument "name" is missing, with no default


I was surprised when I was calculating derivatives (using the library mosaic) in Rstudio like

it says
Error in D(fun ~ x) : argument "name" is missing, with no default

I tried it in R, it turned out the same problem. Anyone could help? Thanks!


From the documentation of D():

D(expr, name)
expr a expression or call or (except D) a formula with no lhs.
name,namevec character vector, giving the variable names (only one for D()) with respect to which derivatives will be computed.

Edit: I ignored part of the docs myself, before.

D won't accept a formula as expr. Try D(expression(x^2), "x").


Thanks for the help! I also found another code to solve this problem “deriv”. Thank you again~