7

What is the reason behind quoting the name of your function? I have seen this in a couple of packages (for example line number 2 here in the quantmod package). Instead of writing

f <- function(x)

they write

"f" <- function(x)

Another example is from the gratia (line 88) package where functions are back quoted:

`f` <- function(x)
4
  • "for example here in the quantmod package" Please provide a line number.
    – Roland
    Commented Aug 31, 2020 at 7:56
  • 5
    It doesn't make any difference for the functions in the link you shared. It appears to be more of a stylistic choice from the developer to allow the top of function declarations to stand out. Sometimes it is necessary to wrap function names in quotes if they contain illegal characters. The most frequently seen ones in R are the [<- type operators. That is, if you want to define a function that writes to a subset of a custom class so the user can do x[y] <- z then you need to write a function like "[<-.myclass" <- function(y, z) {...} Commented Aug 31, 2020 at 7:57
  • 2
    You need to quote names, if they are not syntactically valid.
    – Roland
    Commented Aug 31, 2020 at 7:57
  • @Roland, I have updated my question, but I use f instead of the actual function name
    – J.C.Wahl
    Commented Aug 31, 2020 at 8:02

1 Answer 1

0

Transferred from Allan Cameron's comment.

It doesn't make any difference for the functions in the link you shared. It appears to be more of a stylistic choice from the developer to allow the top of function declarations to stand out. Sometimes it is necessary to wrap function names in quotes if they contain illegal characters.

The most frequently seen ones in R are the [<- type operators. That is, if you want to define a function that writes to a subset of a custom class so the user can do x[y] <- z then you need to write a function like "[<-.myclass" <- function(y, z) {...}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.