library(pracma)

f ( a ) + f ( a ) ( x a ) + f 2 ! ( x a ) + f 3 ! ( x a ) + f ( 4 ) 4 ! ( x a ) + . . .

1 + x + x 2 + x 3 + x 4 + x 5 + O ( x 6 )

Taylor_equation1 <- function(x) {1/(1-x)}
p <- taylor(Taylor_equation1, x0 = 0, n = 4)
p
## [1] 1.000029 1.000003 1.000000 1.000000 1.000000

1 + x + x 2 2 + x 3 6 + x 4 24 + x 5 120 + O ( x 6 )

Taylor_equation2 <- function(x) {exp(x)}
p <- taylor(Taylor_equation2, x0 = 0, n = 4)
p
## [1] 0.04166657 0.16666673 0.50000000 1.00000000 1.00000000

x x 2 2 + x 3 3 x 4 4 + x 5 5 x 6 6 + O ( x 7 )

Taylor_equation3 <- function(x) {log(1+x)}
p <- taylor(Taylor_equation3, x0 = 0, n = 4)
p
## [1] -0.2500044  0.3333339 -0.5000000  1.0000000  0.0000000