Mil*_*der 4 r function quantmod
以下是R函数的前几行:
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>
}
Run Code Online (Sandbox Code Playgroud)
当我将两个股票代码作为函数参数传递时,我需要用引号将它们括起来:
teetor("GLD", "GDX")
Run Code Online (Sandbox Code Playgroud)
我希望能够简单地输入:
teetor(GLD, GDX)
Run Code Online (Sandbox Code Playgroud)
有几种方法可以做到这一点,但通常我不会建议.
通常调用没有引号的东西就意味着对象本身就在搜索路径中.在不指定的情况下执行此操作的一种方法是使用该with()
功能.
您可以通过以下方式获取某些内容的名称而不实际存在deparse(substitute(...))
:
> blah <- function(a) {
deparse(substitute(a))
}
> blah(foo)
[1] "foo"
> foo
Error: object 'foo' not found
Run Code Online (Sandbox Code Playgroud)
所以原则上你可以deparse(substitute(...))
在你的teetor
函数中使用上面的例子来获取名称,而不是传入名称.