【发布时间】:2014-01-29 12:18:59
【问题描述】:
我编写了接受时间序列对象的函数,我想将输入数据强制转换为 xts 格式,但是当我这样做时, deparse(substitute()) 会出现问题,它应该返回对象的名称。
重现错误的代码:
library(xts)
data(sample_matrix)
matrixObj=sample_matrix
myFunc=function(data){
print(deparse(substitute(data)))
}
myFunc(matrixObj)
[1] "matrixObj" #这就是我想要的。
myFunc2=function(data){
data=as.xts(data)#add this line to coerce data into xts format
print(deparse(substitute(data)))
}
myFunc2(matrixObj)
[1] "结构(c(50.0397819115463, 50.2304961977954, 50.420955209067, "
[2] "50.3734680543285, 50.2443255196795, 50.1321122972067, 50.0355467742705, "
[3] "49.9948860954217, 49.9122834457642, 49.8852887132391, 50.2125821224916, "
[4] "50.3238453485025, 50.4635862266585, 50.6172355897254, 50.620241173435, "
[5] "50.7414981135498, 50.4805101188755, 50.4138129108681, 50.3532310036568, "
[6] "50.1618813949374, 50.3600836896748, 50.0396626712588, 50.1095259574076, "
[7] "50.2073807897632, 50.1600826681477, 50.0604060861532, 49.9658575219043, "
...缩写...
【问题讨论】: