Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reason to add quotation marks around R function names?

Tags:

syntax

function

r

What is the difference between defining a function called myfunction as

"myfunction" <- function(<arguments>){<body>}

and

myfunction <- function(<arguments>){<body>}

furthermore: what about the comments which are usually placed around such a function, i.e.

#myfunction{{{

 "myfunction" <- function(<arguments>){<body>}

#}}}

are they just for documentation or are they really necessary (if so for what)?

EDIT: I have been asked for an example where comments like

#myfunction{{{

are used: For example here https://github.com/cran/quantmod/blob/master/R/getSymbols.R

like image 597
Ueli Hofstetter Avatar asked Apr 02 '15 14:04

Ueli Hofstetter


People also ask

What are quotation marks used for in R?

A character value is entered into R by using quotation marks: "" or '' . Type in the editor window and run these lines:. The console window should display [1] "this is a character value" and [1] "this is also a character value" on two separate lines.

What is the function or purpose of quotation marks?

Quotation marks (inverted commas) are used for a variety of reasons. They are used to show the exact words someone has spoken or written (a direct quote), or to identify specialist terms. They may also be used to draw attention to words or phrases.

Why do you add quotation marks?

The primary function of quotation marks is to set off and represent exact language (either spoken or written) that has come from somebody else. The quotation mark is also used to designate speech acts in fiction and sometimes poetry.

What do quotation marks mean in programming?

Quote in computer programming In computer programming, quotes contain text or other data. For example, in the below print statement, what you're printing to the screen is often surrounded by quotes. If surrounded by a single quote instead of a double quote, the string is treated as a literal string in many languages.


1 Answers

The quoted version allows otherwise illegal function names:

> "my function" <- function() NULL
> "my function"()
NULL

Note that most people use backticks to make it clear they are referring to a name rather than a character string. This allows you to do some really odd things as alluded to in ?assign:

> a <- 1:3
> "a[1]" <- 55
> a[1]
[1] 1
> "a[1]"
[1] "a[1]"
> `a[1]`
[1] 55
like image 115
BrodieG Avatar answered Oct 01 '22 23:10

BrodieG