Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I eliminate quote marks around parameters in R function?

Here are the first few lines of an R function that works:

teetor <- function(x,y) {

require("quantmod")
require("tseries")

alpha <- getSymbols(x, auto.assign=FALSE)
bravo <- getSymbols(y, auto.assign=FALSE)

t     <- as.data.frame(merge(alpha, bravo))

# ... <boring unit root econometric code>

}

When I pass two stock symbols as function parameters, I need to enclose them with quotes:

teetor("GLD", "GDX")

I want to be able to simply type:

teetor(GLD, GDX)
like image 773
Milktrader Avatar asked Nov 28 '22 03:11

Milktrader


1 Answers

Don't. It's a bad idea to sacrifice clear, simple code just to save a couple of keystrokes. You have created a function that can only be use interactively, not called from another function.

like image 156
hadley Avatar answered Dec 15 '22 10:12

hadley