Error while creating a function

Sir. Thank you for your help. Just an additional doubt. I wrote the code for n(n+1)/2 in a similar manner and didn't receive am error. Could you help in differentiating the two codes.

Sum_first_n <- function(x){

  • n <- x
  • (n*(n+1))/2
  • }

Sum_first_n(5)
[1] 15