The goal of differential
is to provide Automatic Differentiation for
arbitrary R code.
You can install the development version of differential from GitHub with:
# install.packages("pak")
pak::pkg_install("fangzhou-xie/differential")
library(differential)
e <- quote(3*x^2)
gradient(e, wrt(e))
#> 6 * x
e <- quote(3*x^2+a*x^2)
simplify(e)
#> x^2 * (3 + a)