我正在编写一个简单的函数,可以保存两个图,但不幸的是,这是错误的。如何使它工作?
f1<-function(x){
write.table(as.matrix(summary(x)),file="dane.txt",sep=";",row.names=T)
#I want here to make two plots.
png(filename="hist.png")
hist(x)
dev.off
dev.cur()
png(filename="density.png")
plot(density(x))
dev.off
}
由于调用此函数,我收到此消息:
function (which = dev.cur())
{
if (which == 1)
stop("cannot shut down device 1 (the null device)")
.External(C_devoff, as.integer(which))
dev.cur()
}
<bytecode: 0x0000000010dbfaa8>
<environment: namespace:grDevices>
答案 0 :(得分:2)
像这样更改你的代码
f1<-function(x){
write.table(as.matrix(summary(x)),file="dane.txt",sep=";",row.names=T)
#I want here to make two plots.
png(filename="hist.png")
hist(x)
dev.off()
dev.cur()
png(filename="density.png")
plot(density(x))
dev.off()
}
你只错过了dev.off()
的()