Help writing functions

Hi, I am learning to use R, working through an Intro to R book to get a handle on the software. One of the exercises I have to work through is writing functions, and I need to write a function for the area of a circle. This is the function I used & the function that is supposedly correct according to the exercise:
circle.area<-function(d){
pi*(d/2)^2
}
However, I keep getting an error message back that the object 'd' is not found. It is simply supposed to be a variable for diameter, to which values can be inserted. How do I specify that, or define d as a variable? I also tried defining d as "diameter" but it didn't work for some of the more complex equations I have to use this function for.

Can you share the command you run that raises the error? Your function works, so the error's probably coming from somewhere else.

Also, on this forum, you can format code blocks by putting a line with three tick marks above and below the code:

This will show as regular text

```
# This is a code block
x <- 1 + 1
```

Back to regular text

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.