【发布时间】:2015-12-08 15:19:29
【问题描述】:
我正在尝试修改自定义函数中的点 (...)。这是我的plot2 函数的简化示例,它使用type="p"(默认)在屏幕上显示一个绘图,并使用type="l" 保存一个svg。当 ... 绘图选项之一已经在函数中时,问题就会出现。在此示例中,"type" 与多个实际参数匹配。
plot2 <-function(...){
plot(...) #visible on screen
svg("c:/temp/out.svg") #saved to file
plot(...,type="l")
dev.off()
}
#This works
plot2(1:10)
#This does not work because type is redefined
plot2(1:10, type="o")
我尝试将点放在函数内部的list 中并对其进行修改,但plot 不接受列表作为输入。
#Does not work
plot2 <-function(...){
plot(...)
dots <<-list(...)
print(dots)
if("type" %in% names(dots)) dots$type="l"
print(dots)
svg("c:/temp/out.svg")
plot(dots)
dev.off()
}
plot2(1:10, type="o")
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
【问题讨论】:
标签: r